I'm making a 2D game with two spaceships flying around shooting each other. One spaceship is controlled by the user, the by an AI. I want to use a simple Finite State Machine (FSM) for the AI.
I'm trying to make the AI ship follow the player's ship and stop at a given radius from it.
I've got a GetInsidePlayersRadius
state, and a StopMoving
state. But so far I got a weird bug involving the AI ship moving a few pixels, then stopping for a moment, than moving again, creating very fragmented movement.
The AI can move up, down, left, right, up-left, up-right, down-left, or down-right, just like the player.
What could create this fragmented movement behavior, generally when an AI agent is constantly trying to get inside a certain radius from an object, and stop when it's inside it?
How would you implement a following behavior of an AI as part of a Finite State Machine?