Is there a fix for this so no matter what of the 8 I travel its the same speed?
Yes... You want to apply a total force and split it between x and y
To do this for any angle, you apply
± totalForce * sin(angle) in one direction, and
± totalForce * cos(angle) in the other.
Your case is simpler as the angle is fixed at 45 degrees when moving diagonally, and conveniently both
cos(45) are the same ...
0.70710678118 (which happens to be
So multiply your X and Y forces by
0.70710678118 when moving diagonally, and the total will be the same as when moving in a cardinal direction.
Even better... If you use the formulas above instead of the fixed value, it works for any direction including N/E/S/W.
You can get the angle from the player's current rotation around the Y axis.
How would I address this...?
If I've understood correctly and you're concerned about how forces add up over time...
Usually, you apply some form of damping so that movement decreases over time if there's no input.
You can do this a number of ways, but the simplest is probably to calculate the current speed (eg by checking how far the sprite had travelled in the timespan since the last frame) then multiply that speed by some number just below
0.95) and use that as your speed for the next frame.
That way, when you're applying a force, the sprite accelerates and when you let go, it slows down and eventually comes to a stop.
If you can't find a value that feels "just right", there's a lot of research on different ways to damp... Wikipedia's article on Damping might be a good starting point to get some search terms.
Is this equivalent to me irl walking straight 1m/s then turning diag and walking 1ms?
Think in terms of a 2D grid. We'll draw a triangle with the base being how far we travel in X and the side being how far we travel in y.
The hypotenuse is the resulting motion.
Moving Straight up?
- x stays at zero
- y increments by 1
No need to do any fancy calculations as that's obviously 1 unit.
Now let's move diagonally NE...
- x increases by
- y increases by
How long is the hypotenuse? Well, from Pythagoras, it should be
sqrt(x ^ 2 + y ^ 2)
sqrt(0.70710678118 ^ 2 + 0.70710678118 ^ 2)
(Remember I said
0.70710678118 is equivalent to
1/sqrt(2)? This is one reason that's helpful to know ...).
1 / sqrt(2) ^ 2 simplifies to 1/2 or 0.5
So we get
sqrt(0.5 + 0.5)
Which is -of course-
So yes, it's moving at the same speed of 1 unit/s.