Help With Movement Speed Logic?

I’m working on a 3rd-person action-adventure game, and I’m having trouble getting my different movement speeds working correctly together. I have jogging, walking, sprinting, crouching and prone; and essentially, I want sprinting to override all other movement speeds when it’s activated. I also have an aiming state as well, which sprinting will need to override too. I’ve been working with booleans, but there are enough possible combinations of states that the boolean logic just becomes a big mess.

What other method(s) could I use to make the state management cleaner and easier to handle? Enums and switches? I don’t really know at this point.

Hi,

I would switch to enums. So the enum would contain something like “sprint”, “jog”, “walk”, … so all your states, lets call this enum “EMovementType”. Then I would create one function to switch the state. So this function takes a variable of “EMovementType” as input. For the allowed changes I would create a new structure that contains an array of “EMovementType”, lets call it “FMovementTypes”. Then create a variable (map) that maps from “EMovementType” to “FMovementTypes” (input movement type to allowed movement types from there).

So via the current movement type you access the map and get an array of allowed movement types from there. Then you only continue if this array contains the new movement type. If so then do the change, if not do nothing.

That seems like it would work pretty well, but I’m not sure I understand how to set it up properly. Could you maybe post a simple example screen?

Sure, like this