Trouble with states for running and crouching

AndrzejGieralt

New member
Hello! What is the correct way to make use of the states in the character controller? There are so many options it is quite a lot to take in!

What I'd like to do is have the player not be able to run while crouched, slow down while crouched, and be able to run/sprint while standing. I tried 2 things.

1) I tried to add a new Speed Change ability that had the same start/stop as crouch, and a speed multiplier of 0.4 or 0.6 (tried a few speeds) - this worked great, except when I jumped, I was now no longer able to change the height when crouching. After a jump, regardless of if I jumped from crouch or from run, I would no longer change height after crouching (but, prior to jumping, I could change height). Before jumping, if I crouched, I could see that Height Change and my second Speed Change were both active when pressing the crouch key, but after jumping, when I crouched, only the second speed change was active, and the height change would no longer activate.

2) I also tried doing 2 different presets in the Speed Change ability instead. I created a preset for Run and added the speed mult and start stop that run had, and another preset for crouch using a speed mult of 0.4 and the same start/stop as crouch. When doing this, it behaved unpredictably. While running, if I released shift, I would not stop running until I stopped moving. If I crouched, my speed stayed the same until I hit shift, which seemed to slow me properly but as a toggle, that would also stop slowing me if I stopped and started moving again. Do I have to do something to the defaults of the Speed Change ability?

Tangentially, I get the utility of having all these abstractions but I love being able to just overwrite everything by throwing scripts on top of things. Like just have a script that will set the movement speed regardless of the state or something... handle my own sneak/crouch related logic in a separate script and do everything there... and just not worry about the underlying systems - one might think, well that just defeats the point of using an asset, just write it yourself - but, I appreciate the core functionality, I appreciate the rewired integration and not having to worry about the physics and all the intricacies of making a controller feel good - but would still like to be able to just inject whatever I want over top without having to learn the entire domain of the asset. Maybe that's just what you get when using an extensive and highly generic system like this.
 
I think that it'll be easier to answer this by saying what direction I would take for each of your goals:

not be able to run while crouched
When the Height Change ability is active you can add a new state to the Speed Change ability that disables the ability. This will prevent it from being able to start.

slow down while crouched
If you are using root motion then this is based on the animation and not anything state related. In the case of root motion you will need to replace the animation within the animator controller so there is a slower moving animation.

If you are not using root motion then you can use the state system. For this when the Height Change ability is active you'd change the Motor Acceleration values on the Character Locomotion component.

run/sprint while standing
This is the default setup so there's no changes necessary for this.
 
I see, thank you. I have several questions about this for clarification.
When the Height Change ability is active you can add a new state to the Speed Change ability that disables the ability. This will prevent it from being able to start.
How can I add a new state to the speed change ability that is only active under certain conditions? It seems that when you crate a new state using a preset, you can activate it using an action, for example Crouch (which I have set up in rewired as Left Control). Do you also need a separate state for running? What happens if you add a second state for running like I did, does it sort of double up with the "default" settings of the ability? How do you create a state that disables the ability (I'm not at my desktop right now - I'm guessing you can just add it as a property when creating the state preset?)
If you are not using root motion then you can use the state system. For this when the Height Change ability is active you'd change the Motor Acceleration values on the Character Locomotion component.
So I can't create a new Speed Change ability and change its multiplier, or create a new preset and change its multiplier? How do I cause the height change to alter parameters on a separate component like Character Locomotion? It seems very intuitive that you would just create a new preset that sets the multiplier to like 0.5 and activate it on Crouch, I want to properly learn how to use this so it would be very appreciated if you could explain why this is the wrong approach.
 
How can I add a new state to the speed change ability that is only active under certain conditions? It seems that when you crate a new state using a preset, you can activate it using an action, for example Crouch (which I have set up in rewired as Left Control). Do you also need a separate state for running? What happens if you add a second state for running like I did, does it sort of double up with the "default" settings of the ability? How do you create a state that disables the ability (I'm not at my desktop right now - I'm guessing you can just add it as a property when creating the state preset?)
Input and the state system are separate. Input will trigger an ability, which will then activate a state. Have you seen the video on this page? It gives a good intro to the state system. Your end result would look like this:

1699974773518.png

Where the preset sets the enabled property:

1699974811418.png

The name of the state is determined by the State field on the ability. You can add the same preset to any number of Speed Change abilities.

So I can't create a new Speed Change ability and change its multiplier, or create a new preset and change its multiplier? How do I cause the height change to alter parameters on a separate component like Character Locomotion? It seems very intuitive that you would just create a new preset that sets the multiplier to like 0.5 and activate it on Crouch, I want to properly learn how to use this so it would be very appreciated if you could explain why this is the wrong approach.
You could create a new Speed Change ability, similar to programming there are multiple ways to accomplish a given task. In this case though I think that it's easier to adjust the Character Locomotion component while the Height Change ability is active since you always want that to occur versus based on an input.
 
Top