Source engine - movement code: What is "wishspeed"?

1.3k Views Asked by At

I've been looking into the Source Engine lately. More specifically, the strafing/bunnyhopping sort of movement they have.

https://github.com/ValveSoftware/source-sdk-2013/blob/56accfdb9c4abd32ae1dc26b2e4cc87898cf4dc1/sp/src/game/shared/gamemovement.cpp#L1779

Here is the actual movement code for the source engine. My question points towards line 1779 and 1784. Here, wishspeed is given a value of wishdir's magnitude. Although when a vector (wishdir) is a normalized vector, wouldn't the magnitude be normalized too? (So it would be a magnitude of 1)

To my understanding that's what happens when something is normalized. If this is true, why is there an if statement of line 1784 with if ( wishspeed != 0 && **(wishspeed > mv->m_flMaxSpeed)**), if wishspeed is 1? Looking further into the code, there's more hinting towards wishspeed not being either 0 or 1, but a higher value.

Could someone explain to me how this is possible? How can wishspeed be over 1 when it should've been normalized?

Thanks!

2

There are 2 best solutions below

0
On BEST ANSWER

From developer.valvesoftware.com on float VectorNormalize(vec) :

Divides the vector by its length, normalising it. Modifies the Vector and returns the old length.

wishspeed takes the length the wishdir had before it was normalized.

0
On

On this page the operation is documented:

https://developer.valvesoftware.com/wiki/Vector

VectorNormalize() returns the original length of the vector.