I am making a flight simulator game in XNA. I also have several blimps(Airships) that moves around the map. The problem is that I can’t get the blimps to turn around properly when they get to the end of the map. I have a Blimp class with contains position, a rotation variable and speed. This is the basic logic, which says that they are going to start rotate when they are getting near an edge, but I don’t know how to make them stop rotating after turning a specific amount(lets say 180 degrees).
private void blimpLogic(GameTime gameTime)
{
float turningSpeed = (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f;
float turning = 0;
foreach (Blimp b in blimps)
{
if (b.Pos.X <= terrain.EdgeX.X + 100)
{
turning += turningSpeed * b.Speed;
b.Rotation += turningSpeed;
}
if (b.Pos.X >= terrain.EdgeX.Y - 100)
{
turning += turningSpeed * b.Speed;
b.Rotation += turningSpeed;
}
if (b.Pos.Z <= terrain.EdgeZ.X + 100)
{
turning += turningSpeed * b.Speed;
b.Rotation += turningSpeed;
}
if (b.Pos.Z >= terrain.EdgeZ.Y - 100)
{
turning += turningSpeed * b.Speed;
b.Rotation += turningSpeed;
}
}
}
Thanks in advance and ask if I am being unclear on something.
Given the “stop turning” operation will take place when the blimps are away from the edges you cannot base it on the blimp’s position (after all the player might want to get close).
So you need to include some additional state with each blimp
turningFromTheEdge, and if this is set and the blimp is no longer near the edge then stop turning.