Hey guys, so I successfully figured out how to (for the most part) take the mecanim deltaPosition and use it to change a rigidbody’s velocity. It was pretty simple really;
Instead of saying:
transform.position += anim.deltaPosition;
I implemented rigidbody velocity to get a more realistic movement:
rigidbody.velocity.x = anim.deltaPosition.x*60;
rigidbody.velocity.z = anim.deltaPosition.z*60;
rigidbody.rotation *= anim.deltaRotation;
Now, it was working perfectly until I added another character into the scene with a different avatar, but same controller. I ran the game, and through some debugging, I found out that the characters were actually moving twice as fast as before. More importantly, I found out that their deltaPositions were doubled. Puzzled, I removed one of the characters, and then it worked perfectly again. How was the deltaPosition increased with the addition of another character? Is there anyway around this?
Update: Does not only occur with more avatars. Occurs whenever frame rate goes down.
The reason you are seeing an increased delta position when the frame rate decreases, is because the delta is showing you how far the anim has moved this frame.
Because the frame took longer, more of the animation took place.
The reason you are seeing the characters moving faster is because you are multiplying the delta position by a constant value.
This might work “perfect” for the frame speed you were on with one character, but when you have a slower frame speed, your velocity will be being set to a much bigger value. You want to know how far they are moving per consistent time unit, not how far they are moving a frame, to set the velocity.
What you want to do is something like the mecanim examples on the asset store. Their nav mesh example sets the velocity like this:
agent.velocity = animator.deltaPosition / Time.deltaTime;
You should be able to do the same and see similar results. You can then apply your speed modifier to the result of animator.deltaPosition / Time.deltaTime get them to be faster/slower afterwards.