- Home /
Question by
rendingfang · Feb 16, 2014 at 12:35 AM ·
animationfollowpcfollowing
Animation Stops Unexpected. (Script included)
I am trying to code a script that allows a secondary character to follow my player controlled character. She follows fine, but whenever I say to play "walk" animation while following she stops the first animation.
The other thing that is bothering me is that when the play knocks into her she doesn't move back. It's a puzzle game with tight spaces so I need to to move back when the player collides with her. I thought of a collision box, but eventually I'm going to make it so that you can switch between her and another character.
Here's the script:
void Update () {
Debug.DrawLine (target.position, myTransform.position, Color.cyan);
//Look at target, and go towards
animation.Play("idle"); //This plays fine.
myTransform.rotation = Quaternion.Slerp (myTransform.rotation, Quaternion.LookRotation (target.position - myTransform.position), rotationSpeed * Time.deltaTime);
//Stop and wait for me.
if (Vector3.Distance (target.position, myTransform.position) > maxDistance) {
animation.Play("walk"); //Plays first frame and freezes? Is this suppose to be loop?
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
Comment