I want the object or zombie in this case to face the direction of is movement, I have a script that cause random movements for the zombie but it never faces the direction of travel
var speed : Vector3;
var timing :float;
function Start() {
speed = Vector3(Random.Range(-359, 359),0,Random.Range(-359, 359));
timing = 0;
}
function FixedUpdate() {
timing+=Time.deltaTime;
rigidbody.MovePosition(rigidbody.position + speed * Time.deltaTime);
if(timing > 3){
ChangeDirection();
timing = 0;
}
}
function ChangeDirection () {
speed = new Vector3(Random.Range(-359, 359),0,Random.Range(-359, 359),0); }
You have to rotate it to face the direction in which he is moving. So every time you change the direction he is moving you rotate him so he will face it
Yes. You’re going to want to evaluate that every time. For a Javascript variable, use var instead of Vector3. Other than that, the code should work.
And yes, put it in fixed update.