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

Adjust walk cycle stride length at runtime

Discussion in 'Animation' started by tigger, Mar 2, 2019.

  1. tigger

    tigger

    Joined:
    Jan 8, 2013
    Posts:
    95
    I have a humanoid character and a walk cycle animation imported via FBX, assigned to an Animator, etc.
    It's simple enough to vary the speed (frequency) of the animation to match the horizontal speed the character is moving (translating).

    Question: Is there a way via scripting to change the length of the walk cycle's stride at runtime? I'd like to be able to shorten or lengthen the stride by an arbitrary amount based on runtime conditions. e.g., instead of a stride being 1 meter, increase to 1.25 meters, or shorten to 0.75 meters.

    Thank you.
     
  2. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    it's not easy to do. but maybe it's doable with IK.

    you need the position of the foot, the distance from the center-of-mass and checking where the foot reaches max
    and adding IK target based on those +adjusting offset.z.
     
  3. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,553
    Unity doesn't give you access to any stride information, or even any animation data at runtime. So you would need to evaluate the animation in the editor to calculate the stride yourself then use IK to adjust the feet at runtime.
     
  4. tigger

    tigger

    Joined:
    Jan 8, 2013
    Posts:
    95
    Ok, thank you. I'm in the process of implementing an IK-based approach. Was wondering if there were alternatives / off-the-shelf solutions.