Search Unity

Mecanim - Control torso through script?

Discussion in 'Scripting' started by Deleted User, Feb 21, 2013.

  1. Deleted User

    Deleted User

    Guest

    I can make the head look at a target easily enough using the animator.SetLookAtPosition, and I've got the hands/arms moving correctly now with the SetIK functions. But is there a way to rotate particular bones in script? Instead of just turning the head, I would like to rotate the entire torso slightly left/right as well. Or even make the character bow/bend over at the waist.

    Can those only be achieved with actual animation clips and not through scripting with the new animator?
     
  2. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    If you use a lookAt object and move that left or right and up or down and set the various head and body weights per type of motion you are trying to simulate you can control the whole upper torso via translating the lookAt object around, snapping it to points of interest and adjusting or tweening weights to make the rotations. I keep the lookSAt object in the local avatar hierarchy so I can be pointing any direction and still know -x is left and -y is down from the avatar POV.

    The issue I am trying to solve that brought me to this thread is I would like the user or dev to set pelvic root height. I have the Controller set up to go to eight different martial arts stances. To create variances or styles for individual setup devs or users may want to narrow or widen or lengthen the default stance. The first setting would be low, mid, high to set the pelvic root height. It doesn't seem to set whether using MatchTarget or by directly setting animator.bodyPosition = myVector3(myX, myY, myZ). The feet should remain locked and the legs should bend at the knee and ankle to accommodate the scripted stance position. They don't. If the y value is higher it brings the feet up off the ground even though the IK pass is on and foot IK is on and weighted to 1.0. If I lower it it doesn't do a thing as though rock solid in that stance.

    What is the trick here? Simply setting the bodyPosition should do the trick but doesn't.


    TIA
     
  3. Cyril A

    Cyril A

    Joined:
    Aug 9, 2013
    Posts:
    3
    Hi,

    I've the same issue than Ottoelite....
    I've tryed to use the SetLookAtPosition and it zorks fine with the head...
    And I would like it to work the same from the torso. But I don,t find how. That's how I find this topic.
    And reading your answer I understand this is possible but I can,t understand how.
    Especially "set the various head and body weights per type of motion". Could you better explain how to do in order to configure a lookAt from the torso ?
    Thank you very much in advance.
     
  4. HamFar

    HamFar

    Joined:
    Nov 16, 2014
    Posts:
    89
    Hi guys,
    Has any of you figured this out by now?
    I have a similar problem, so I thought your solution(s) might help me too...
    Thanks