[5SD033]Potato Pirates, Week One – The beginnings of an AI

The first few days of this week was spent planning how our AI should behave. We started by outlining the different states of the enemy:

  • Patrol State – The default state of the enemy plane. When in this state the enemy will patrol a certain area. It will do this by randomizing a waypoint within its area which it will then travel towards, when the waypoint is reached it will randomize a new waypoint and so on.
  • Chase State – When the enemy has found a player it will abandon its patrol route and instead chase after the player, shooting at them when they are in range.
  • Search State – The enemy will move into the search state after the player has successfully escaped the enemy by hiding in clouds or using power-ups. In this state the enemy will search within a certain distance of where the player was last seen. After a set amount of time it will go back to patrolling its designated area. If it finds the player it will instead begin chasim them.
Bloggbild
The player(the red plane) is within the enemy’s(the yellow plane) “field of vision”

I took it upon myself to give the enemy a “field of vision”, an area around the enemy which when the player enters will make the enemy move into chase state an begin chasing the player. This was done by drawing a circular shape around the enemy. The collision box around the circle was still rectangular,  so the player would only need to enter the rectangle. I got around this by getting the difference in X and Y positions of the player and the enemy while the player is inside of the collision box. Then using the pythagorean theorem to get the distance between them, if the distance was lower than or equal to the radius of the circle the enemy would “see” the player.

We chose to have a circular field of vision to simulate the enemy pilot being able to turn their head and look around, the radius of the field of vision is so short so the player will have a chance against the enemies. As of now the enemy does not actually do anything when the player enters its field of vision, it only writes “I see you” to the console. We intend the field of vision to increase slightly when the player have been found to make it a bit harder for the player to escape the enemy/enemies. Every type of enemy will also have slightly different fields of vision, the Anti-Aircraft gun for example will have a much larger field of vision than any other enemy but will not be able to chase the player since it is mounted and can not be moved easily.

About Bengt Hagnelius

2015 Programming