So i wanted to ask if this is good practice or if there’s a more efficient way of doing this.
I have a character who can run and by hitting a Key (V or Shift) can sprint
I also want to use the same keys, to allow for a crouch sprint (V or Shift)
So in the screenshot I just created a branch and passed a condition to determine if the user was crouching (True) or (False)
If True the user would FLIP FLOP between 2 variables defined to Set the Max Walk Speed Crouched
Also i reflected this with variables defined if the user was running in a normal stance.
Is there a better way to do this. I guess im asking is there a cleaner way to do this ??
Thanks
You can use a “Select Node” to set your Max Speed. You would plug in the “Is A” boolean from the Flip Flop node into the select node and plug in your variables into the right pin. That way you could delete one set max walk speed and one set max crouch speed.
What are the flip flops for? Is the idea that “sprint” will toggle sprinting, instead of being held down while sprinting?
The way I would personally write this, is to make the inputs set state – keep a “is sprinting” and a “is crouching” flag in the playercontroller.
Then, each time either of these change, call a “derive speeds” function which switches on the different states, and updates the appropriate values.
Also, the “derive walk/sprint speed” function doesn’t need to know whether you’re crouching; it can just update both of them.
So, you’d get:
On Input Crouch: toggle the crouching bool; call into character controller to set the crouch state.
On Input Sprint: toggle the sprinting bool; call the update-speeds function, which reads sprinting and sets both the max crouched and max uncrouched speeds.
I would recommend that you create an Enumerator for your player’s states (crouch/standing, etc.) instead of using a boolean. Enumerators will help you understand what is going on better, a lot of booleans will make you confused as your code gets more complex.
You can then use the enumerator to select your speed.