Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Animation Rigging: How to - foot placement on stairs or slope ?

Discussion in 'Animation Rigging' started by Banksy, Jun 8, 2019.

  1. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    376
    How would I go about using Animation Rigging to place the character's feet so they can walk up an angled ramp ensuring the sole of each foot aligns to the surface it is climbing ?
    This would also be appropriate for walking up stairs or any uneven ground.

    On an uneven surface, the ankle would rotate accordingly & the sole of the foot should not penetrate the ground.

    Is this now possible using Unity's new Animation Rigging system ?

    Sure would love to see an example of this in action.
     
    Last edited: Jun 8, 2019
    wilsonillustration likes this.
  2. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    658
    With the TwoBoneIKConstraint you can set the positions of the feet - where this position is, is up to you.
    As your sole is probably not aligned with the foot-bone you'll probably want to use an empty parent with the "rigTransform"-Component, so the IK-Target position is correctly set for the foot bone, when you place the parent on the floor.
    Hierarchy:
    -FootIKHolder_L (can be placed exactly on the floor)
    --FootIK_L (is the target for the TwoBoneIKConstraint)
    In a lot of foop-placement-solutions I've seen, animation curves where used (which can be setup in the UnityEditor) to have readable data when the foot is in the air and when it is on the floor.

    Usually you can then simply read the bone-transform-position in LateUpdate and retarget it to a point on the floor (which you can get by a simple raycast, including the normal) but as the animationRigging package updates the animation stream before LateUpdate happens, you'd have to take a slightly different approach.

    You could setup some cyclic motion for your IK Target (Holder) aligned with the animation-curve you've created and based on the current speed of the character to get your raycast positions (probably in the Update method, or if you have a rigidbody character, maybe in FixedUpdate (as your character position will only change on FixedUpdate)) and then set the IK Target (Holder) based on the raycast like in the example before.
    Only diffrence here is that you have to get the feet-positions based on the movement of the character and not from the animation itself.

    Everything else would need a specific self-written constraint I guess.