Download

How to enumerate character input direction relevant to camera

I’ve been scratching my head for quite some time on how to approach this and I’m hoping someone can point me into a direction I can really dig into.

Essentially I have a default third person game with the default follow camera and I would like to create a system where an enumeration can be set based on the character input direction. There are five points of direction to be enumerated: forward (character moving away from camera), backwards (character moving towards camera), left (strafe), right (strafe), and none (for no movement input). Z axis is zeroed and not factored in. The reason I want this relevant to the camera is because if the character rotates and runs towards the camera I still want this to “register” and be set as backwards. The trick is only one direction point must be set at a time as I’m planning to fire events based on the set enumeration direction (switch on enumeration). For example if using WASD keys for movement input then if W is pressed first I would want the enumeration set to forward and remain set even if multiple keys are then being pressed. Once W is released then the enumerated direction can be reset by the current direction or default back to the none if there is no movement input. Perhaps an array is best where I set direction based on index 0 and it’s first-in and first-out? I’m running into a wall trying to do this with input axis events as I’m trying to avoid using input action keys as I would like this functionality to work on a gamepad as well (perhaps set direction based on four ranges within 360 degrees). Please let me know any suggestions or what I should look into to build this.

You can use this kind of setup to limit key input:

](filedata/fetch?id=1831531&d=1605120309)
or

Looks like I’ve been overthinking this! This definitely put me on the right track. Your post was very helpful, thank you.