I am working on a project that utilizes multiple characters on screen using the Locomotion System to walk around the environment. Every few minutes a global dance event occurs, where all the characters stop where they are, face the camera, and dance in unison to the music. This works great so far, however when they get to the end of the dance, and it’s time to start walking around again, they seem to get stuck on the last frame of the dance animation. They will move around the environment according to the input values given to them, but they won’t animate the walk/run cycles properly.
Here’s a snippet from my controller script:
void Update () {
// get vector towards person being tracked
if(person.wasUpdatedSinceLastCheck()){
lastUpdate = Time.time;
}
Vector3 directionVector = person.getPosition() - transform.position;
// Make input vector relative to Character's own orientation
directionVector = Quaternion.Inverse(transform.rotation) * directionVector;
// adjust speed
directionVector *= walkMultiplier;
if(!dancing){
// Apply direction
motor.desiredMovementDirection = directionVector;
} else {
motor.desiredMovementDirection = new Vector3(0,0,0);
// check if still dancing
if(!animation.IsPlaying("Thriller")){
dancing = false;
}
}
And here is the method in the super class for the controllers attached to all of my characters that causes them to dance:
public void dance(){
Vector3 v = Camera.main.transform.position - transform.position;
v.x = v.z = 0.0f;
transform.LookAt(Camera.main.transform.position - v);
animation.CrossFade("Thriller");
dancing = true;
}