Im trying to get the movement direction to set the max walk speed depending on which side character moves, like if we are strafing, we are getting lower speed. If we move backward, we move even slower and etc.
So the thing is Im trying to get the character moving direction.
I want to get when character moves:
Only Forward
Only Backward
Only Horizontal
Only Diagonal forward
Only Diagonal backward
I get the dot product of forward and right vector to velocity (so I called it X and Y).
but the problem didn’t go away, and i still get unstable X/Y Dot product results depending on FPS. So when FPS is alright, its doing great, but when it comes really low, it starts to messing up.
The question is, am I even doing right? Is there any easiest way to calculate the movement direction of the character? I know its probably the most complicated way, but I wasn’t told about another ways.
The reason you’re getting “unusable” results is because you’re not getting the dot product’s ACOSd (arccos (degrees) )
And yes the easier approach would be just comparing the normalized velocity to your character’s forward vector as the usage of the right vector is obsolete. You’d only need the angle between the movement direction and the character’s forward vector to calculate your desired speed.
Also keep in mind that acos never produces negative results so you’d need to negate the result if the movement direction is pointing to the left. This is where you can make use of the right vector. Because if the angle between the movement direction and the character’s right vector is over 90 degrees, it means you need to negate the result of the acos before setting it to your variable.