How do I properly get the direction of moving?

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:

  1. Only Forward
  2. Only Backward
  3. Only Horizontal
  4. Only Diagonal forward
  5. Only Diagonal backward

I get the dot product of forward and right vector to velocity (so I called it X and Y).

And it’s going great until the fps is getting low. I tried to move it from event tick to Set timer by event,

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) ) :innocent:

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.

2 Likes

Thanks a lot. But I found a class that calculates that (the “calculate direction” one lol)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.