I have an enemy that I would like to move as follows:
Start at (0, 200, 0)
Move to (200, 0, 0)
Move to (0, -200, 0)
Move to (-200, 0, 0)
Move to start point, repeat as long as it remains active.
This is what I've done to achieve that:
if (position.X < 200 && position.Y > 0)
{
Velocity = new Vector3(1, -1, 0) * speed;
}
else if (position.X >= 200 && position.Y <= 0 && position.Y > -200)
{
Velocity = new Vector3(-1, -1, 0) * speed;
}
else if (position.X <= 0 && position.Y <= -200)
{
Velocity = new Vector3(-1, 1, 0) * speed;
}
else
{
Velocity = new Vector3(1, 1, 0) * speed;
}
It moves to the second point, but then gets stuck and appears to vibrate in place. How should I be doing this?