- Home /
Follow object by Transform.Rotate
Hello! I have two objects - first is Player and second is Enemy. Enemy must look at Player, but I can't set 3 axis - so I can't use "transform.LookAt". I need only to set y axis. So - I have idea to do that by "transform.Rotate". And maybe raycast to detect Player... You have idea to code that?
Thanks in advance and sorry for my english ;)
Comment
Answer by Cherno · Mar 12, 2015 at 10:02 PM
You can use Transform.LookAt and immediately afterwards set the eulerAngles of the axis that the transform should not rotate around to 0.
transform.LookAt(playerTransform);
transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);
Your answer
Follow this Question
Related Questions
Camera rotation around player while following. 6 Answers
Multiplied LookAt 0 Answers
[Help] Object flips around when using transform.Rotate 3 Answers
Object movement / rotation error 0 Answers