UTIL AngleDistance: Difference between revisions
Jump to navigation
Jump to search
Note:You'll probably want to use UTIL_AngleDiff instead!
No edit summary |
Thunder4ik (talk | contribs) m (→top: Unicodifying) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{DISPLAYTITLE:UTIL_AngleDistance}} | ||
UTIL_AngleDistance does '''a similar''' thing to [[UTIL_AngleDiff]], but does not clamp in a range from - | UTIL_AngleDistance does '''a similar''' thing to [[UTIL_AngleDiff]], but does not clamp in a range from -180° to 180°. Instead, it brings them up to 360° closer to these values. | ||
{{note|You'll probably want to use [[UTIL_AngleDiff]] instead!}} | |||
== Usage == | == Usage == | ||
<source lang=cpp> | <source lang=cpp> |
Latest revision as of 02:08, 9 January 2024
UTIL_AngleDistance does a similar thing to UTIL_AngleDiff, but does not clamp in a range from -180° to 180°. Instead, it brings them up to 360° closer to these values.

Usage
//-----------------------------------------------------------------------------
// Purpose: Returns the difference between two values as a float.
// Input : next - Value "B" to compare against
// Input : cur - Value "A" to compare with
// Output : float - Difference between the two values, interpreted as an angle
//-----------------------------------------------------------------------------
inline float UTIL_AngleDistance( float next, float cur )
Examples
//Note! In this example they used the UNCLAMPED version (UTIL_AngleDistance is UNCLAMPED),
//Instead of the pre-clamped version (UTIL_AngleDiff)
//They then clamp the value. This is only provided for documentation's sake
//But it's probably just easier to use UTIL_AngleDiff which will always be between -180 and 180.
// Move toward target at rate or less
float distX = UTIL_AngleDistance( angles.x, GetLocalAngles().x );
vecAngVel.x = distX * 10;
vecAngVel.x = clamp( vecAngVel.x, -m_pitchRate, m_pitchRate );
SetLocalAngularVelocity( vecAngVel );