- Home /
rotate on the Y axis
hello i have an enemy that looks at me and chases me and stuff but it rotates on all the axis to look at me so how do i make it rotate on only the Y axis to look at me? Heres what i've got at the moment.
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.position - transform.position),rotationSpeed * Time.deltaTime);
Thanks.
Comment
Answer by Ashkan_gc · Apr 27, 2011 at 02:45 AM
create the rotation vector like this.
rotationVector = target.position - transform.position;
rotationVector.y = transform.position.y;
then pass this to Slerp.
ins$$anonymous$$d of target.position - transform.position put rotationVector in your LookAt function. that subtraction creates a vector from you toward the target but you should change the y as you see.
Your answer
Follow this Question
Related Questions
eulerAngles.y always returns 179.9999 1 Answer
Locking world rotation of child 1 Answer
LookAt once 0 Answers
Lock rotation axis? 4 Answers
Joint Transform Rotation in Unity? 0 Answers