Page 1 of 1

Forward + Strafe Keys = Doubled Movement Speed

Posted: 2012-10-17, 13:46
by sphyrth
Yup. I must admit that this shows how low my code-reading abilities are.

May I know what's causing my forward and strafe speed to double only when I press the forward key together with a strafe key?

Re: Forward + Strafe Keys = Doubled Movement Speed

Posted: 2012-10-17, 18:51
by HWGuy
There's a condition missing, when you press forward you move at 1x, and when you press strafe you move at 1x sideways, which combined is 1.4x diagonally. A little func which decreases movement speed when you press two keys to move diagonally would solve that.

I forgot how to mod the original movement code, fixed it once but then dumped it for newer code someone made a sample for.

Re: Forward + Strafe Keys = Doubled Movement Speed

Posted: 2012-10-17, 23:10
by Carsten
HWGuy wrote:There's a condition missing, when you press forward you move at 1x, and when you press strafe you move at 1x sideways, which combined is 1.4x diagonally.
Exactly right, this is the situation:
forward_and_strafe.png
forward_and_strafe.png (2.74 KiB) Viewed 2842 times
The fix is simple: Just (re-)normalize, that is, scale back to unit length, the movement vector. As a result, all vectors will have length 1 and movement speed is the same in any direction.

Do you want to implement this yourself?
I can do it, too, but it's a nice exercise to get familiar with the code. ;-)

Iirc, it's the WishVelocity in HumanPlayer.cpp that represents the vector in the above image. I also seem to remember that someone had the same question before, not long ago, but at the moment, I cannot find the related thread.
In any case, if you want me to have another look at this, please let me know. :up: