- Home /
root Motion and physics2D
Hello, I have a little problem with the animation of a character. More specifically, it affects root-motion.
It's a 2D character. So far I have realized the character's movements via Unity's physics system (eg rigidbody2d.velocity).
Now, though, I have a movement that does not work that well (climbing one edge), so I thought I was using root-motion.
The problem now is that physical forces no longer seem to work properly on the figure.
I use, e.g. rigidbody2d.velocity to run the character to the left or right, nothing happens.
The figure stays in place, regardless of whether the root animation is active at the moment. (Forces up and down still seem to work).
Once I delete the said animation from the animator, everything works as usual.
"Generate root motion curves" was activated for the animation. "Apply root motion" has also been activated.
Can it be that it's just not possible to use root-motion and the physics system on the same character, or am I missing something?
Answer by TheSky · Dec 06, 2017 at 05:21 PM
If anyone has the same problem, I have a possible solution. The problem only occurs in the 2017.X versions of Unity. In version 5.6.4 for example, everything works normally.
As for the error, I now know about where the problem is and how to handle it.
The problem is actually different than I first thought. The problem is not that the Physik2D system does not work when root-motion is enabled. The Physik2D system works well.
The problem is that for some reason, rigidbody2D.velocity is overridden when root-motion is enabled.
Since the problem probably originates from the animator component, the problem can be easily avoided.
I have created an additional script.
For this script, under edit --> "Project Setting" -> "Script Execution Order" must be set to be evaluated after the default time.(that way the script will not run until all other scripts have done their thing).
I now store rigidbody.velocity in the update method and assign the stored value to the rigidbody.velocity component in the late-update method (which is evaluated after the animator component).
I do not know why rigidbody2D.velocity will be overwritten, but at least for me the problem is solved.
So I am also struggling wiht animations, physics and root motion. I think I know how to solve it. I made a small video, where you can see different scenarios. https://youtu.be/8grSV-5E7Gc
So topone woks as you would excpect because it doesn't have animation contoller at all. But the last one works exactly the same with rigidbody and push force from FixedUpdate(). The trick is to add Position property to you active animation. It doesn't matter if you use it or not in this animation state, but if there are no position property in the active animation you will ancounter your problem as I think. Hope that helps.
Your answer