Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How i can change body rotation on animation play?

Discussion in 'Animation' started by nscyber, Aug 26, 2014.

  1. nscyber

    nscyber

    Joined:
    Jul 14, 2014
    Posts:
    22
    I have one player
    - I use mecanim of unity.
    - have 3 Base layer.
    1.base layer
    2.TopBaseLayer
    3.BottomBaseLayer

    question.
    1.I wan't to change rotation of "top body" on mouse look left,right,top or bottom.

    I use mouse look of FPS unity script it don't work,because it have change all body not top body.
     
    Last edited: Aug 26, 2014
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    If you have Unity pro, you can use the built-in IK.

    Put a avatar mask on your TopBaseLayer and check IK Pass.
    For the mask, Select only the upper body part if you are using a humanoid rig or select each transform that you want to affect if you are using a generic rig.
    On your GameObject you will have to create a monobehaviour script and define the message callback OnAnimatorIK
    see doc for more information:
    http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnAnimatorIK.html
    http://docs.unity3d.com/ScriptReference/Animator.SetLookAtPosition.html
    http://docs.unity3d.com/ScriptReference/Animator.SetLookAtWeight.html

    If you don't have Unity Pro you will have to find an IK plugin on the asset store or you could tweak the mouse look script and rather than applying the rotation on the root transform you could apply it to upper body transform.

    Best regards,
     
  3. nscyber

    nscyber

    Joined:
    Jul 14, 2014
    Posts:
    22
    oh thank you.
    i have one problem.
    On i add mouse look script to spine of model and change Axes is mouseY,on play model can change on mouse Y but model will return to transform default animation not change to new transform.
     
  4. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Hi nscyber,

    One thing I forgot to mention is when you modify a transform driven by the animation system, either legacy or mecanim, you need to write you script code in the void LateUpdate() callback, otherwise your new value will be overwritten by the animation.

    see doc
    http://docs.unity3d.com/ScriptReference/MonoBehaviour.LateUpdate.html

    Best regards,