Advertisement
Advertisement
| 07.21.2008 at 06:45AM PDT, ID: 23581758 | Points: 200 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: |
position += new Vector2((float)Math.Sin(CurrentAngle) * Velocity * Elapsed, (float)Math.Cos(CurrentAngle) * Velocity * Elapsed);
float TargetAngle = (float)(Math.PI) - (float)Math.Atan2(target.Y - position.Y, target.X - position.X);
if (target.X == position.X)
{
TargetAngle = (float)(Math.PI * 0.75f);
}
if (target.Y == position.Y)
{
TargetAngle = 0;
}
float angleDelta = Math.Abs(CurrentAngle - TargetAngle);
if (angleDelta >= RotationSpeed * Elapsed)
{
// We need to cap to RotationSpeed
if (AngleDirection(CurrentAngle,TargetAngle))
{
CurrentAngle += RotationSpeed * Elapsed;
}
else
{
CurrentAngle -= RotationSpeed * Elapsed;
}
}
else
{
// We can rotate without limitation!
CurrentAngle = TargetAngle;
}
|