Unity3D Mecanim animation system Generic animation supports displacement in animation

Since the game we are currently working on may not have a strong demand to use the latest Humanoid animation in the Mecanim animation system, our first choice will be to use Generic animation, so there is a long way to go. Waiting for you to plant in front. After confirming that you want to use Generic animation, then continue. Because the old animation system (Legacy) was used in previous projects, the animations of all characters and NPCs are done at the origin. Characters and NPCs need to use scripts to control the displacement of characters while playing animations. This requirement is responsible for the program Working closely with the children's shoes responsible for the animation to adjust the character animation displacement to a coordinated state, this is of course not a particularly difficult thing, but if the animation can be directly brought to the displacement, then both the program and the art children's shoes are liberated, and the animation design Time can be bolder, after all, the real displacement of the character animation is more coordinated than the program control, and everyone saves a lot of things, why not do it. Having said a lot of nonsense, well, back to the topic. Then make a continuous animation with displacement. After importing into Unity and creating the Animator Controller, set the action and click the Play button to see the effect. Nima, I found that the character does move during the playback of a single animation, but when the animation returns to the IDLE state after each animation ends, the position of the character in the scene will flash back and return directly to the beginning of the animation The position of the character during playback, and throughout the animation, the position of the character has never changed, and the Capsule Collider tied to the character will not move at all, and it is completely behind the character. What is the problem? This problem did not occur when I was using Humanoid animation. I tried to restore the Humanoid animation type again, and confirmed that this displacement flashback problem does not occur under the Humanoid animation type. After each animation ends, the position of the character This is where the animation ends.

After searching for a long time, I finally found a solution. In fact, you only need to specify the root node of the animation skeleton when importing the animation.

咱们对比一下这两个设置的选项,其中Humanoid动画类型导入时,根本就不需要设置Rig的根节点,而Generic动画就需要设置,而且默认设置是none,所以需要手动指定为模型对应骨骼的根节点。

看来Unity动画支持Apply Root Motion这个特性的实现机制就是根据骨骼在动画中的位移在引擎内进行计算滴,如果我们选择使用Humanoid动画的话呢,肯定需要设置一个人形的骨骼Avatar信息,这个Avatar信息中就会包含骨骼各个节点的信息,其中当然也包含了根节点(或者说已经不需要根节点了,因为所有关键的骨骼信息都会映射到Avatar信息上)。而对于Generic动画呢,Unity自身并不清楚骨骼之间的关系,而Apply Root Motion这个特性就是根据骨骼位移自行计算的,那么就需要我们手动地指定动画使用的骨骼的根节点了,根据根节点在动画中的位置变化就可以动态计算出来对象在场景中实时的位置了。

下图就是修改Root Node设置之后动画播放时的效果了,Capsule Collider也实时跟着动画的播放改变位置了。

Guess you like

Origin blog.csdn.net/Ling_SevoL_Y/article/details/129467627