0

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!

mads232
  • 339
  • 1
  • 5
  • 14
  • 2
    I'm not familiar with the source, but perhaps `VectorNormalize` normalizes the vector but also returns the magnitude prior to the normalization? The normalization would have to calculate the magnitude to do the normalization so I don't think its unlikely that it could return it as a general optimization. – kmdreko Feb 24 '17 at 22:05

2 Answers2

3

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.

François Andrieux
  • 28,148
  • 6
  • 56
  • 87
2

On this page the operation is documented:

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

VectorNormalize() returns the original length of the vector.

Bas in het Veld
  • 1,271
  • 10
  • 17