Unity3d's Mecanim Animation system learning Note (vii): IK (Inverse dynamics) animation

Source: Internet
Author: User

What is IK?

IK (inverse kinematics) is reverse dynamics, that is, you can use various objects in the scene to control and influence the movement of the body parts of the character, in general, skeletal animation is the traditional drive from the parent node to the child node (i.e. positive dynamics), and IK is reversed, The Skeleton parent node is driven by the child nodes of the bones, for example, if the character walks on the stone, it needs to be driven by the child nodes of the foot to make the whole skeleton to be a stepping stone response.

IK can make people and scenes more fit, so as to achieve a more realistic game effect, if you play "Prince of Persia" or "Assassin's Creed" series, should be the protagonist's climbing and Feiyanzoubi ability is impressive, these are applied IK, so that the animation fit into the specific scene of the performance.

The unity3d itself already has the IK function (http://docs.unity3d.com/Manual/InverseKinematics.html), and we'll go through the simple learning and use of IK in the next step.

Finalik

The plugin is an optimization and enhancement of the IK of unity itself, which can simulate a more realistic effect and is interested to see.

https://www.assetstore.unity3d.com/cn/#!/content/14290

Instance

Let's take a look at a small example of how IK should be used in Unity3d, and we'll create a scene that keeps the head of the character facing one point at a time, while creating four points to control the movement of the character's hands and legs.

We add a character and 5 balls to the scene as follows:

According to the information given in the official unity document, you must first turn on IK Pass on the animator layer that requires the IK animation, as shown in:

Only if this option is turned on will the system invoke the appropriate IK method.

Here we add a script for this character, as follows:

 1 using Unityengine; 2 using System.Collections; 3 4 public class Testik:monobehaviour 5 {6-Transform lookattarget; 7 8 public Transform Lefthandtarget ; 9 Public Transform righthandtarget;10 public Transform leftfoottarget;11 public Transform rightfoottarget;12 1 3 Private Animator _animator;14, Start (), _animator = this. Getcomponent<animator> ();}19 void Onanimatorik (int layerindex) {if (_animator! = N ull) 23 {24//Only the head follows the change of _animator. Setlookatweight (1); 26//The body will follow, the radian changes greater//_animator. Setlookatweight (1, 1, 1, 1); if (lookattarget! = null), {_animator. Setlookatposition (lookattarget.position);}32 _animator. Setikpositionweight (Avatarikgoal.lefthand, 1); _animator. Setikrotationweight (Avatarikgoal.lefthand, 1); if (lefthandtarget ! = null) _animator. Setikposition (Avatarikgoal.lefthand, lefthandtarget.position), _animator. Setikrotation (Avatarikgoal.lefthand, lefthandtarget.rotation),}40 _animator. Setikpositionweight (Avatarikgoal.righthand, 1); _animator.                 Setikrotationweight (Avatarikgoal.righthand, 1); if (lefthandtarget! = null) 44 {45 _animator. Setikposition (Avatarikgoal.righthand, righthandtarget.position); _animator. Setikrotation (Avatarikgoal.righthand, righthandtarget.rotation);}48 _animator. Setikpositionweight (Avatarikgoal.leftfoot, 1); _animator.                 Setikrotationweight (Avatarikgoal.leftfoot, 1); n-if (lefthandtarget! = null) 52 {53 _animator. Setikposition (Avatarikgoal.leftfoot, leftfoottarget.position); _animator. Setikrotation (Avatarikgoal.leftfoot,leftfoottarget.rotation)}56 _animator. Setikpositionweight (Avatarikgoal.rightfoot, 1); _animator.                 Setikrotationweight (Avatarikgoal.rightfoot, 1); if (lefthandtarget! = null) 60 {61 _animator. Setikposition (Avatarikgoal.rightfoot, rightfoottarget.position); _animator. Setikrotation (Avatarikgoal.rightfoot, rightfoottarget.rotation); 63}64}65}66}

It is important to note that the script that controls IK must be added to the Onanimatorik method to take effect, see below:

Unity3d's Mecanim Animation system learning Note (vii): IK (Inverse dynamics) animation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.