Forward + Strafe Keys = Doubled Movement Speed

Get technical support about the C++ source code and about Lua scripts for maps, entities, GUIs, the console, materials, etc. Also covered are the Cafu libraries and APIs, as well as compiling, linking, and the build system.
Post Reply
sphyrth
Posts:15
Joined:2012-09-11, 13:40
Forward + Strafe Keys = Doubled Movement Speed

Post by sphyrth » 2012-10-17, 13:46

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?
HWGuy
Posts:95
Joined:2011-05-31, 07:37

Re: Forward + Strafe Keys = Doubled Movement Speed

Post by HWGuy » 2012-10-17, 18:51

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.
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Re: Forward + Strafe Keys = Doubled Movement Speed

Post by Carsten » 2012-10-17, 23:10

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.74KiB)Viewed 11742 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:
Best regards,
Carsten
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests