AngleToAngle
Introduction
Turning towards angle
using FlatRedBall.Math;
using FlatRedBall.Gui; Sprite sprite; sprite = SpriteManager.AddSprite("redball.bmp");
sprite.ScaleX = 4; float cursorX = GuiManager.Cursor.WorldXAt(0);
float cursorY = GuiManager.Cursor.WorldYAt(0);
float differenceX = cursorX - sprite.X;
float differenceY = cursorY - sprite.Y;
if (differenceX != 0 || differenceY != 0)
{
double angle = Math.Atan2(differenceY, differenceX);
float angleDifference = (float)MathFunctions.AngleToAngle(
sprite.RotationZ, angle);
const float minDifferenceForSmoothing = .04f;
if (Math.Abs(angleDifference) < minDifferenceForSmoothing)
{
sprite.RotationZ = (float)angle;
}
else
{
const float rotationSpeed = 2;
sprite.RotationZVelocity = Math.Sign(angleDifference) * rotationSpeed;
}
}
Range Checks
Last updated
Was this helpful?