Animatorcontroller inverse kinematics ik

Source: Internet
Author: User

By using inverse kinematics ik, we can control the role of a particular part of the body to rotate or move as needed to achieve some of the desired effects, such as: when moving, let one foot with injury drag; Let your hands lift up to get the apples on the table, and keep your head facing our color camera as if it were watching us all the time.

Let's start with a simulated wounded foot:
Before doing this, check the Ikpass property in the character's animation state machine, applying IK's layer:

Then, under the character object, create an empty sub-object iktarget, and place it in the right ankle.
Finally, add the script to the character Ikcontroller:

1 usingUnityengine;2 usingSystem.Collections;3  4  Public classIkcontroller:monobehaviour5 {6      PublicTransform Target;//ik target7      Public BOOLikactive;//whether IK is available8     PrivateAnimator Anim;9  Ten     voidAwake () One     { AAnim = Getcomponent <Animator> (); -     } -   the     //ik control to write in the Onanimatorik Method! -     voidOnanimatorik () -     { -         if(ikactive) +         { -             //Specifies the IK weights of the body parts to be controlled, 1 is enabled, and 0 is not enabled.  +Anim. Setikpositionweight (Avatarikgoal.rightfoot,1); AAnim. Setikrotationweight (Avatarikgoal.rightfoot,1); at   -             //set the target value for IK - Anim. Setikposition (Avatarikgoal.rightfoot, target.position); - Anim. Setikrotation (Avatarikgoal.rightfoot, target.rotation); -         } -     } in}

Set Target to our just created empty object Iktarget, run the game, let the character move animation play up, you can see the right foot of the animation is not playing, but dragged away. We can change the position and rotation of the iktarget in the scene view, the right foot of the protagonist will also move, of course, this can also be controlled by code.

One more control character has been staring at the color head:
Put the color camera in front of the character and add a bit of code to the script above:

1 anim. Setlookatweight (1); 2 // look here              , eyes . 3 Anim. Setlookatposition (Gameobject.findwithtag ("maincamera"). transform.position);

OK, run the game, move the color camera, don't keep looking at people, ah, will be shy ^^!

Animatorcontroller inverse kinematics ik

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.