I’ve been having issues with mecanim, and precision control of a character in my game world.
I have setup animations in maya, utilizing root motion so I can control the characters position in maya (instead of code).
I have been very careful in animating to ensure that a walk / run / jump / roll… etc… cycle has a very exact distance traveled. So for example when my character runs I know that at the end of a step, he will be exactly 2 units away from the last step. I also have a leaping animation for use when grabbing an edge that is 4 units away from the last step.
My thinking here is so that when I setup my world every obstacle will be setup via grid snapping so hands grab bars / ledges, feet land on ramps / walls / ground etc. Other than these types of actions the user will not control the steering or speed of the character, so precision is very important since the user will not be able to correct.
My problem is that using root motion (and I have played with all the baking options within unity for orientation, y, xz) gives you inherently unpredictable results. For example if my leap animation starts when the run cycle is at 99% instead of 100% the slight rotation of the pelvis causes the character to jump slightly to the side instead of forward. I have setup my transitions so that a bool must be true (set by user via input or by trigger at the start of a gap) and the animation exit time is 1 with 0 blending between clips (Note to unity tech: we need input fields here instead of just sliders… Interestingly if you remove an animation from a state then view the transition you get fields because unity is unable to show a “preview” of the transition)…
In my mind this should result in something similar to a video editing timeline where one clip swaps for another, at the exact world position that the previous clip ended (yes animations line up from one to the other)
Maybe the problem is since deltaTime is variable you can’t guarantee a clip will ever be at exactly 100% so root motion isn’t where I would expect it to be?
Maybe I’m going about this all wrong and should use the legacy anim system, and control my character position via code ( but unity claims the legacy system will be phased out, so this should be possible in mecanim… perhaps use mechanim, but remove root motion)?
Maybe I need a bone in my hierarchy that supersedes the pelvis that has 0 rotation and 0 weight to the verts and use that as my root motion ( I don’t see this working for complex animations that involve lots of turning / twisting ) ?
In a related matter:
I am trying to make my actions a little more dynamic by changing the jump length / height Thinking that I should just be able to modify rootPosition in LateUpdate() over the span of the animation, I have so far been unable to get it to respond at all. Yet updating rootRotation works. Example.
anim.rootRotation += additiveRotation; // THIS WORKS.... New rotation value (I'm currently getting this from mobile device tilt amount )
anim.rootPostion += new Vector3(0, 2 * Time.deltaTime, 0); // DOESN'T WORK... This should raise the character up 2 unit per second, but has no effect.
Any Ideas / insights?
I so far have not seen any tutorials / manual that goes beyond the very basics of mecanim. Anybody have links?
Thanks for reading, I know it wasn’t short.
Unity 4.0.1f2 Free
Windows 7 x64