- Home /
look at target problem
i am using the
transform.lookat(target);
TO MAKE MY ENEMY LOOK AT THE PLAYER now if you try this you can see if we go close to the enemy and jump he will lie down somehow first i wanted to ignore him TO look at my y posittion! now i dont know that is a good idea or not because enemy is dynamic and i think when following me that make problems if i do that
Answer by robertbu · Mar 21, 2014 at 04:06 PM
The typical way is to move the target point before doing the LookAt():
var pos = target.position;
pos.y = transform.position.y;
transform.LookAt(pos);
Alternate code that does the same thing:
var dir = target.position - transform.position;
dir.y =0.0;
transform.rotation = Quaternion.LookRotation(dir);
hi tnx but its not working when i go near enemy he runs from me
Answer by whydoidoit · Mar 22, 2014 at 08:16 AM
Robert's answer is good. In case you need examples I specifically cover this in a tutorial on Unity Gems: http://unitygems.com/quaternions
Your answer
Follow this Question
Related Questions
problem with LookRotation on simple AI 0 Answers
NavMesh agent won't rotate around Y axis 0 Answers
What's wrong with my AI script. 3 Answers
AI Lookat script Only using the z axis 2 Answers
issue with AI shooting other AI 0 Answers