- Home /
LookAt without Y axis
i have this on my enemy AI script:
transform.LookAt(Vector3(target.position.x, transform.position.y, target.position.z));
i wrote transform.position.y instead of target.position.y to make the enemy stay on him Y position.
but it gives me errors, someone can help me?
transform.LookAt(new Vector3(target.position.x, transform.position.y, target.position.z));
As @DESTRU$$anonymous$$TORR indicates, 'new' is only necessary in this context when using C#.
Answer by DESTRUKTORR · Aug 31, 2013 at 05:00 AM
You should paste those errors, here, so we can try to tell you what's going wrong, but the thing that sticks out to me is that I'm going to assume you're using C#, and you forgot the "new" keyword in front of Vector3? It should look like this:
transform.LookAt(new Vector3(target.position.x, transform.position.y, target.position.z));
Answer by Paulius-Liekis · Aug 31, 2013 at 06:56 PM
transform.LookAt(new Vector3(target.position.x, transform.position.y, target.position.z));
Your answer
Follow this Question
Related Questions
Lock rotation axis? 4 Answers
Inverse the mouse position value 2 Answers
Sliding cube around on x/z axis with a constant y-axis 0 Answers
Bone lookat do not work Help! 1 Answer
Closest target acquisition using Physics Overlap Sphere script not working 1 Answer