Forum rules - please read before posting.

Stairs & Animation

In a 3D Direct Controlled game, using the character controller, how would you go about having walking & running animations on stairs, not triggered through interactions? It seems the normal walking and running animations my character uses are giving too much momentum when using stairs, so the character often runs off each step before being brought back down with gravity.

Foot placement is not an issue as I am using Final IK.

Comments

  • edited February 2020

    Animation and motion are separate - are you looking to slow their velocity, or the playback of animation?

    A script to alter the walk/run speed based on the floor's angle can be found on the wiki: https://adventure-creator.fandom.com/wiki/Changing_character_speed_with_slope_angle

    For animation changes, you can define a "Vertical movement float" parameter in the Player Inspector, and use this in your Animator to alter which walk/run animations get played according to its value. This parameter will turn positive when rising, and negative when lowering.

    Also: if you're using a Rigidbody + Capsule Collider combination, you may also have better results with a Character Controller instead so far as the "flying off at the end" effect goes.

  • Great, thanks Chris. That wiki has become a real gold mine for AC additions.

  • I'm having a hard time getting vertical movement to turn positive. I can get it to turn negative a small amount, but it seems to be not enough to use Vertical Movement on it's own to activate transitions, so I've added an extra OnStairs bool to make sure the animator knows to change animations.

    Still though, I need the positive vertical movement values, otherwise I can't play the "ascending" animations.

    Am I doing this right? I have two blend trees: one for going up stairs, and one for going down. Both have their relevant walk and run animations and an idle stance.
    Both of these blend trees can transition to the normal locomotion animations (which work without issue).

    But yeah, I can only seem to get walking/running down stairs to work.

    https://imgur.com/a/0CUbiwq

    https://imgur.com/a/GQkSANc

  • Ignoring the transitions and use of your parameters for a moment, what raw values are you getting for the VerticalMovement parameter? Try pausing the game and viewing the live Animator when moving up/down.

    There should be no difference in the way the value is calculated based on direction - it should be purely the difference in Y-position between frames. Depending on your needs, it may be that you need to rely on a separate parameter that's scaled / lerped based on this one. For example, if you defined an additional Animator Parameter named e.g. ScaledVerticalMovement - and relied on that for your transitions instead - a simple script could convert one to the other:

    void Update ()
    {
        float rawMovement = GetComponent <Animator>().GetFloat ("VerticalMovement");
        float currentScaledMovement = GetComponent <Animator>().GetFloat ("ScaledVerticalMovement");
        float newScaledMovement = Mathf.Lerp (currentScaledMovement, rawMovement * 10f, Time.deltaTime * 5f);
        GetComponent <Animator>().SetFloat ("ScaledVerticalMovement", newScaledMovement);
    }
    
  • VerticalMovement never goes above 0.02 (or -0.02) I don't think (it moves very fast at these lower values, so it's hard to pinpoint). I've paused it a few times and that's the highest I've ever seen it.

    I may have the Parameter/Threshold too high for activating walking up stairs animations. For walking up stairs I have it set to 0.1, but for going down I have it set to -0.1.

    I think where it gets difficult is, when transitioning from normal movement, you can only set it to change at greater than or less than amounts, whereas the blend tree changes at exact amounts. This could be where I have gone wrong, because the way the transition requirements are set are actually impossible to reach.

    I'll keep tinkering. I really wish there was a way to get Unity's Character Controller to just stick to a surface though. There are dedicated assets for it on the store of course, but AC plays along just fine with the built-in one with much less hassle.

  • If the values are lower than the thresholds you've set, using the script above to scale it up would be a way around that.

  • Sorry, I was going to try your script but I'm getting this error:

    Assets\Eden_Game\ScaledVerticalMovement.cs(1,6): error CS0116: A namespace cannot directly contain members such as fields or methods

  • You'd need to post the full script - I can't glean much from the error message alone. Be aware that the code I posted above is meant to replace a new script's default Update function - not replace the whole file.

  • Ah, no longer a problem. After I posted this last reply, I found that by just a closer matching of the threshold values for transitions between blend trees makes it work a lot more reliably - no additional script required (the Slope Speed Control script is helping out here though, as it lowers the movement speed accordingly).

    Thanks again.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.