Reputation: 113
transform.LookAt(target.position);
I'm trying to use this code to have a AI lookAt the enemies but it looks way to high.
Upvotes: 2
Views: 3137
Reputation: 6132
A little more information would be nice. How are the objects placed in the hierarchy? Is target
a parent or a child object?
What transform.LookAt
does is pointing the transform.forward
at the target's position.
Can you try transform.LookAt(Vector3(target.transform.position.x, transform.position.y, target.transform.position.z);
?
If that doesn't work, can you try adding transform.Translate(Vector3.forward * Time.deltaTime);
?
With the last code you can see the object moving towards the target. That way you are sure it's pointing the right direction. Maybe you think it's looking too high because your model is wrong.
Upvotes: 2