Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Animation movement help

Discussion in 'Animation' started by Maxske, Dec 16, 2015.

  1. Maxske

    Maxske

    Joined:
    Feb 20, 2015
    Posts:
    37
    Hello, I made and animated a human model for my unity game. When i use it in unity, everything works well.
    I just want to know how to make it so that if i look up, the top half of my body looks up. How might I go about doing this?
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,533
    Use Inverse Kinematics. Add a small script that has an OnAnimatorIK method. In this method, use SetLookPosition and SetLookWeight.

    The look position should be a transform (such as an empty GameObject) that specifies where the character should look. When you look up, move this GameObject up. Depending on your setup, you could do this by making the GameObject a child of the camera.
     
    theANMATOR2b likes this.
  3. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Or something like this :
    Code (csharp):
    1.  
    2. void OnAnimatorIK(int layerIndex)
    3. {
    4.    Vector3 TenFowardTheCenterOfTheScreen = new Vector3(0.5f, 0.5f, 10.0f);
    5.    Vector3 lookTarget = Camera.main.ViewportToWorldPoint(TenFowardTheCenterOfTheScreen);
    6.    MyAnimator.SetLookAtWeight(1.0f, 0.8f, 0.8f, 0.0f, 5.0f);
    7.    MyAnimator.SetLookAtPosition (lookTarget);
    8. }
    9.  
    10.  
     
    Last edited: Dec 18, 2015
    TonyLi likes this.
  4. Maxske

    Maxske

    Joined:
    Feb 20, 2015
    Posts:
    37
    Thanks for the help! But I am completely new to the IK stuff so I cant get it to work