I'm attempting to use UnitySteer as my pathfinding script(s) while using mixamo motion-capture animations via the scripts they've provided. Individually I can get them each to work; separately I get some weird results. It seems (sometimes) that if I have more than one instance of the animation running one of them will play through once and freeze at the end; even with the animation set to loop.
Thats a small issue and one I can probably sort out on my own. The real issue I'm having (and it could very well be because I don't entirely understand the UnitySteer autonomous vehicle script) is that the Mixamo driver script was written with the assumption that the character is player-controlled. Specifically: it looks for keystrokes to cue the animations. I've tried various forms of CharacterController.velocity to make it work, but I've been getting strange side effects such as moving sideways while walking forward or randomly flying 80ft in a random direction.
I'm posting the mixamo script below..It's rather lengthy, but seems to be fairly straight forward. It does rely on another mixamo script, but from what I've seen that one's completely devoted to regulating the animation's motion-capture side effects(mostly forward movement in the actual animation).
Is there any simple way to get unitySteer to work with this? I've done what I can think of, and I'm sure there's some simple solution I've neglected to consider.
using UnityEngine;
using System.Collections;
public enum MovementMode
{
Human,
Zombie
}
[AddComponentMenu("Mixamo/Demo/Root Motion Character")]
public class RootMotionCharacter : MonoBehaviour
{
public float turningSpeed = 90f;
public RootMotionComputer computer;
public CharacterController character;
public MovementMode mode = MovementMode.Human;
void Start()
{
// validate component references
if (computer == null) computer = GetComponent(typeof(RootMotionComputer)) as RootMotionComputer;
if (character == null) character = GetComponent(typeof(CharacterController)) as CharacterController;
// tell the computer to just output values but not apply motion
computer.applyMotion = false;
// tell the computer that this script will manage its execution
computer.isManagedExternally = true;
// since we are using a character controller, we only want the z translation output
computer.computationMode = RootMotionComputationMode.ZTranslation;
// initialize the computer
computer.Initialize();
// set up properties for the animations
animation["idle"].layer = 0; animation["idle"].wrapMode = WrapMode.Loop;
animation["walk"].layer = 1; animation["walk"].wrapMode = WrapMode.Loop;
animation["run"].layer = 1; animation["run"].wrapMode = WrapMode.Loop;
animation["zombiewalk"].layer = 2; animation["zombiewalk"].wrapMode = WrapMode.Loop;
animation.Play("idle");
}
void Update()
{
float targetMovementWeight = 0f;
float throttle = 0f;
// turning keys
if (Input.GetKey(KeyCode.A)) transform.Rotate(Vector3.down, turningSpeed*Time.deltaTime);
if (Input.GetKey(KeyCode.D)) transform.Rotate(Vector3.up, turningSpeed*Time.deltaTime);
// forward movement keys
// ensure that the locomotion animations always blend from idle to moving at the beginning of their cycles
if (Input.GetKeyDown(KeyCode.W) &&
(animation["walk"].weight == 0f || animation["run"].weight == 0f))
{
animation["walk"].normalizedTime = 0f;
animation["run"].normalizedTime = 0f;
}
if (Input.GetKey(KeyCode.W))
{
targetMovementWeight = 1f;
}
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) throttle = 1f;
// blend in the movement
if (mode == MovementMode.Human)
{
animation.Blend("run", targetMovementWeight*throttle, 0.5f);
animation.Blend("walk", targetMovementWeight*(1f-throttle), 0.5f);
// synchronize timing of the footsteps
animation.SyncLayer(1);
}
else
{
// ensure that the locomotion animations always blend from idle to moving at the beginning of their cycles
if (Input.GetKeyDown(KeyCode.W) &&
(animation["zombiewalk"].weight == 0f))
{
animation["zombiewalk"].normalizedTime = 0f;
}
animation.Blend("zombiewalk", targetMovementWeight, 0.5f);
}
}
void LateUpdate()
{
computer.ComputeRootMotion();
// move the character using the computer's output
character.SimpleMove(transform.TransformDirection(computer.deltaPosition)/Time.deltaTime);
}
}