- Home /
Rotate object towards velocity?
I have an MMO game im working on and to save data sent over the network i will be using this method(If i can figure it out) the zombies in my game have coordinates that they will walk towards and i would like to know a script that would rotate the zombie towards the direction its walking with math equation. Is it possible to have just the "Green" handle rotation also known as the "Y" rotation? I'm using Javscript. Thanks!
Heres my script
//Set public variables public var zombieId = 0; var nextX = 0; var nextY = 0; var nextZ = 0;
function Update () { //Only move players that have valid ids if(zombieId > 0){ transform.position = Vector3.Lerp(transform.position, Vector3(nextX, nextY, nextZ), Time.deltaTime * .5); transform.rotation = Quaternion.LookRotation(rigidbody.velocity);
}
}
function updateNextPosition(posX, posY, posZ){ nextX = posX; nextY = posY; nextZ = posZ; }
Answer by Clydeicus · May 15, 2011 at 08:16 PM
Put transform.LookAt(transform.position + Vector3(nextX,nextY,nextZ));
in your Update method
Your answer
Follow this Question
Related Questions
how to rotate velocity/ tying movement to camera 0 Answers
Rotate Rigidbody Towards Velocity? [3d] 0 Answers
rotate 2d object toward movement 1 Answer
Orbit around an object 0 Answers
How to measure Speed? 2 Answers