- Home /
Question by
cj_coimbra · Oct 17, 2011 at 01:50 PM ·
rotationtransformvector3waypoint
Rotations and waypoints
I have a GameObject that walks around using waypoints. How can I make it match it´s direction (rotation) to the next point it is moving towards? I mean, I want it to be "facing" the next waypoint (Vector3) as if it was walking in a direct line.
Comment
Best Answer
Answer by cj_coimbra · Oct 17, 2011 at 02:18 PM
I´ve done it this way and it works close enough:
//just keep the original y to avoid strange behaviors while walking up or down stairs Vector3 newDirection = new Vector3(target.x, transform.position.y, target.z) - transform.position; transform.rotation = Quaternion.LookRotation(newDirection.normalized);