Question by
Deekayz · Dec 18, 2015 at 12:22 AM ·
animationscripting problemmovement
Make an NPC turn around when it reaches a point
Hey everyone. I have an NPC that is walking back and forth between two points, but he always faces the same direction. How can I get the NPC to turn around and face the direction he's walking once he reaches the point. Here's my script, thanks in advance!
#pragma strict
var pointB : Vector3;
function Start () {
var pointA = transform.position;
while (true) {
yield MoveObject(transform, pointA, pointB, 3.0);
yield MoveObject(transform, pointB, pointA, 3.0);
}
}
function MoveObject (thisTransform : Transform, startPos : Vector3, endPos : Vector3, time : float) {
var i = 0.0;
var rate = 1.0/time;
while (i < 1.0) {
i += Time.deltaTime * rate;
thisTransform.position = Vector3.Lerp(startPos, endPos, i);
yield;
}
}
Comment