Review latest PR formatting
This commit is contained in:
parent
4583987fb9
commit
af744b07c3
1 changed files with 13 additions and 6 deletions
|
@ -283,15 +283,22 @@ RMDEF Vector2 Vector2Rotate(Vector2 v, float degs)
|
|||
return result;
|
||||
}
|
||||
|
||||
// Move towards Target.
|
||||
// Move Vector towards target
|
||||
RMDEF Vector2 Vector2MoveTowards(Vector2 v, Vector2 target, float maxDistance)
|
||||
{
|
||||
Vector2 result = { 0 }
|
||||
float dx = target.x - v.x;
|
||||
float dy = target.y - v.y;
|
||||
float value = (dx*dx) + (dy*dy);
|
||||
if ( value == 0 || ( maxDistance >= 0 && value <= maxDistance * maxDistance )) return target;
|
||||
float result = sqrtf( value );
|
||||
return (Vector2){ v.x + dx / result * maxDistance, v.y + dy / result * maxDistance };
|
||||
|
||||
if ((value == 0) || ((maxDistance >= 0) && (value <= maxDistance*maxDistance))) result = target;
|
||||
|
||||
float dist = sqrtf(value);
|
||||
|
||||
result.x = v.x + dx/dist*maxDistance;
|
||||
result.y = v.y + dy/dist*maxDistance;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue