简体   繁体   English

Unity Eye跟随玩家2D

[英]Unity eye to follow the player 2D

I'm currently working on a narrative game and don't know how to accomplish something. 我目前正在制作叙事游戏,不知道该如何完成某事。 The game is a 2D platformer so everything is build with sprites. 该游戏是2D平台游戏,因此所有内容均由精灵构建。 I have a scene with trees and the trees have eyes, I want the eyes to follow the player along, but the "pupils" need to stay within the "holes" of the tree. 我有一个树木的场景,树木有眼睛,我希望眼睛跟随玩家,但是“学生”需要停留在树的“孔”内。 I have made separate sprites for both the hole in the tree as well as the pupils of the eye's. 我为树上的洞以及眼睛的瞳孔制作了单独的精灵。 I would prefer to write it in c# :). 我更喜欢用c#编写它:)。

I have also added a concept screenshot, so you can get an impression about what i'm trying to accomplish. 我还添加了一个概念屏幕快照,因此您可以对我要完成的工作有印象。

http://imgur.com/pGCV8Uy http://imgur.com/pGCV8Uy

Many thanks to the person who can explain to me how to accomplish this! 非常感谢可以向我解释如何实现此目标的人!

Well I suppose you could use a joint to restrict the yellow pupils to stay within the holes of the eyes. 好吧,我想您可以使用关节来限制黄色瞳孔留在眼孔内。 在此处输入图片说明 Then you could use C# to calculate the relative Vector between the character and the pupil. 然后,您可以使用C#计算字符和瞳孔之间的相对Vector。 Guide the pupil to go in the direction of the Vector, and it will be restricted by the joint to stay in the eye. 引导瞳孔朝向量的方向前进,它将受到关节的限制而无法留在眼中。 The would result in the pupil always pointing in the direction of the character while staying in the eye, which is what you want. 这将导致瞳孔始终留在眼睛中,而瞳孔始终指向角色的方向,这正是您想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM