How to know if the player is moving forward or backward in a 3d game?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Hexadotz

The title says it all but for more context i want to know if the player is moving forward or backward no Matter which direction they look at

You can have a variable hold the direction of the player (e.g. 0 means forward, 1 means moving right, 2 means moving backwards, 3 means moving to the left etc.), then have that direction change whenever you press a key (e.g. W for forward would set direction to 0 in this case). The variable that holds the direction doesn’t even have to do anything, in fact, you can just have it hold information that will only be useful to you.

It’s really up to you to define what counts as “moving forward”.

Ox0zOwra | 2022-09-11 19:34

var velocity = vector3.Zero #or Vector3()

func example():

ramazan | 2022-09-11 20:09

:bust_in_silhouette: Reply From: Inces

If You coded movement somehow, You should have enough information to recognize direction. Velocity can be negative. If this doesn’t solve it, how is your movement handled than ?