The Animator component have the following properties:
How to retrieve delta position and delta rotation for currently evaluating frame? I need to override OnAnimatorMove, make some checks for the current delta position, what is about to be applied to the root transform, and then allow it to move with ApplyBuiltInRootMotion or deny the move by setting trigger to play another animation. How to achieve that?
Since no one replied, I reply myself, in case anyone interested in this.
I’ve put logs into Update, OnAnimatorMove, OnAnimatorIK, and LateUpdate. Those logs shown very strange and inconsistent behaviour of those two properties. If you read their values during Update call of your script, you’ll get the position and rotation delta from the previous frame. But after the Update call those values changing and during OnAnimatorMove and later they represent the position change what is about to be applied to the root transfrom.
However, the actual position of the object remains the same during all frame from update to late update. How is it moving? A miracle…
Researching more into logs I’ve found the actual position change happens after next FixedUpdate call. Can someone explain me the logic how the root motion really gets applied to the root transform?
I’m guessing that you’ve got the animator’s update mode set to “Animate Physics”, which would make it move the object’s position in FixedUpdate.
Animator work (the moving of stuff) happens between Update and LateUpdate. I’m guessing that if you’ve got Animate Physics active, the actual position will only move in the physics step.
I have no idea how that works with OnAnimatorMove. Par for the course for the Animator, it’s not documented.
Nope, the animator Update Mode = “Normal” in my setup. But I’ve found a workaround for that. In the OnAnimatorMove i’ve added the following code
According to my experiments, the deltas gets updated between Update and OnAnimatorMove calls. Now my player object is moving when I say it to move. I can check the step and deny or allow it. This makes me happy
But I still do not understand how it works. I wish Unity Technology to publish sources, like they did for the networking engine. Very helpful.
ApplyBuiltinMotion just does what it would have done with no OnAnimatorMove.
I have had this system give very strange results in different circumstances.
Everything I could find really seems to be setup to use the velocity from the root motion to drive a rigid body.
The other values given seem to be inconsistent and I have pretty much moved away from using the root motion system. Other issues you can have are frame rate problems. The values reported seem like they are instantaneous compared to accumulative. So if you were trying to use the root motion for a jump your frame rate would effect the height you would jump.
Im sure there is probably a correct set of settings but I have yet to discover them. It would be a nice system to have working so you could blend between animations with translation etc in them while performing the motion with our own code.
I cleaned up the code and removed all game logic just to show where the problem is. My final goal is to execute part of the game logic when new position is already known, but player object hasn’t moved there yet.
How do you read speed from the animation and apply it to the rigidbody, using deltaPositions or from curves? I’ve tried from curves and got completely unpredictable simulation, position error varied depending on the framerate. On the other hand moving with delta positions gives me quite stable simulation. I believe I got my state machine working pretty accurate. One thing, I never use transition interruption in my controller. Another thing, it’s pretty simple state machine, only about dozen of states controls all motion.
I think it was the velocity parameters. You set your rigid body velocity to them.
I don’t remember where I saw them doing it exactly but it was what I kept coming across in my searches.
Maybe things are working better now. I was using 5.1 or 5.3 I think before.
Hopefully it stays working for you. I was able to do some cool stuff with it but then I would get some other cases that just didn’t seem to work. So I had to give up on it.