Enemy AI

From Random Access Mayhem Wiki
Jump to navigation Jump to search

AI (Artificial Intelligence) is the logic governing how all enemies position themselves and attack the player. In its current state, RAM has three basic tactics which broadly describe this behavior across standard enemies. Each enemy then has states which determine their specific observable behaviors. Based on their tactic, an enemy will move into different states in different ways. Enemies also have a hidden AI level which enables more complex behavior and makes them more challenging, though this is not seen currently.

Tactics

A tactic is defined for a particular enemy in an encounter and will only change under specific circumstances. There are three of these currently in the game.

Rush

A group of enemies with the Rush tactic swarming the player.

Enemies with the Rush tactic are the most simplistic and common. They will approach the player until they are in a comfortable range and attack. This is the tactic which most enemies use.

Camp

Not to be confused with Camp (Router icon.png Router State)

The Camping Steeltoe icon.png Steeltoe in the final encounter of Staff Room, surrounded by enemies with the Defend tactic.

Enemies with the Camp tactic remain within a particular radius of their starting point by default. From this point they will attack the player. If the player is too close to their default point while trying to return, certain enemies can switch to the Rush tactic.

Defend

Six enemies from the 4th room of Staff Room. All of them have the Defend tactic, and stay at their spawn point.

Enemies with the Defend tactic act as a fusion of Rush and Camp tactics. When the player is outside of an area they control, they act as camping enemies, and while within that area they act as rushing enemies. However, no enemy with the Defend tactic has an area greater than one tile at the moment, so any enemy with this tactic is, broadly, indistinguishable from a camping enemy.

States

Enemy behavior is described by a Finite-state machine. A state describes some behavior that an enemy can take. States are transitioned between based on the enemy's tactic, level, and the current situation.

Enemies have a priority when picking states they will enter. Priority will be listed with the respective enemy.

Universal

Diagram of the universal AI.

Enemies have six universal states.

Priority

Not seen in the priority list is Navigate to close range, which enemies will transition to by their own logic.

Idle

The enemy's target velocity is set to 0 every frame, which results in them decelerating. On the frame they enter Idle and every tenth of a second afterwards, they will attempt to choose a different state according to the priority.

Not Aggroed

Enemies will attempt to Return to Home if they are outside of their allowed area — a radius of 10 units from their spawn point for Camping enemies and from any point in the area they control for Defending enemies, except Router icon.png Router, who has a radius of 20 units — otherwise they wait until they can go aggro, whereupon they will choose a different state according to the priority.

Return to Home

This is a behavior that can only be exhibited by non-Rushing enemies.

Upon entering: The enemy will find their home point or the closest point of the area they control and begin to navigate towards it. If they cannot navigate to this point or the player is too close to this point, the enemy will switch tactics to Rush.

While in this state: The enemy will reconsider their path every second by re-entering the state. Upon reaching their target, they simply choose a different state according to the priority.

Pace

Upon entering: The enemy caps its speed to 80. If it is a Defending enemy, it will begin navigating to a random point in the area it controls. If it is a Camping enemy, it will begin navigating to a random point within a 25 unit radius of its home point.

While in this state: The enemy will try to enter a new state every tenth of a second, as with Idle. When the enemy reaches its destination and more than a second has passed, it will wait for a third of a second before re-entering Pace.

Navigate to close range

Upon entering: The enemy queues it's current state to re-enter later. The enemy then determines if it can reach the player. If it cannot, it immediately aborts this state. If it can, it will begin navigating to the place the player currently is.

While in this state: It will re-enter its queued state if there is an unobstructed line between it and the player. Otherwise, it will reconsider its path after a second has passed by re-entering the state.

Escape OOB

For one second, the enemy will navigate to the nearest valid point. Once it either reaches this point or the second passes, it leaves this state, however if it's not in bounds it will enter this state again.

Steeltoe

Diagram of the Steeltoe icon.png Steeltoe AI

Steeltoe icon.png Steeltoes have four unique states.

Priority

Not seen in the priority list is Melee, which Steeltoe icon.png Steeltoes cannot currently do.

Reposition

A Steeltoe locked in the Reposition state, moving across the ideal range line.

Upon entering: The Steeltoe finds a point closer to its ideal range, moving up to 130 units. The new point is within a 180° semicircle, pointing towards the player if the Steeltoe is too far, or pointing away if it is too close. If no such point exits, the Steeltoe transitions to the Navigate to close range state.

While in this state: After two seconds have passed or it has reached its destination, the Steeltoe will enter the Shoot state. If the Steeltoe is an Elite with Reload coroutine.png Reload Coroutine[1], it will ignore this and shoot as soon as it is fully loaded.

Shoot

Upon entering: The Steeltoe sets a timer for 0.5 - 0.2 x AI level seconds. In practice this will always be 0.5 seconds.

While in this state: The Steeltoe will wait for the timer to expire. Once it expires, it will check whether it is fully loaded and on screen. If it is, it shoots and goes on cooldown for 0.5 - 0.25 x AI level seconds. If it cannot shoot, it immediately choose a different state according to the priority.

Navigate within Range

Upon entering: The Steeltoe checks if the player can be reached. If the player cannot be reached, it will choose a different state according to the priority.

While in this state: The Steeltoe will navigate toward the player, entering the Shoot state if it is on screen by 30 units. The Steeltoe will reconsider their path every second by re-entering the state.

Router

Diagram of the Router icon.png Router AI

Router icon.png Routers have six unique states. Only five are implemented.

Priority

Not seen in the priority list is Snipe, which is transitioned to by other states.

Circle

A Router locked in the Circle state, moving around the player.

Upon entering: The Router determines if there is an unobstructed straight line between the itself and player. If there is none, it will enter the Navigate to close range state. Otherwise, it sets a two second timer and picks a random point around the player at its circling radius to navigate to.

Every time Router picks a point there is a 75% chance it picks one close to its current point around the player and a 25% chance it will cross through its circling radius to the other side of the player.

While in this state: The Router will constantly attempt to throw grenades. When it reaches the point it's navigating to, it will pick a new one. When its two second timer expires, it will choose a different state according to the priority. If it ends up more than 200 units from the player, it will transition to the Snipe state. If the Router finds its path is obstructed, it will pick a new point and reverse its movement direction.

Dash Away

Upon entering: The Router generates 10 points 200 units away from the player and picks one that isn't obstructed by terrain. If no such point exists, it will choose a different state according to the priority. It will then set a two second timer and begin charging a dash while moving towards the point.

While in this state: The Router will release its dash every 0.6 seconds to reach its destination[2]. if it's within 75 units of its destination it will begin charging another dash. Once it reaches the destination or the two second timer expires, it will enter the Snipe state.

Snipe

Upon entering: The Router determines if the player can be sniped — whether the player is more than 75 units away and within throwing distance based on its current velocity. If it cannot snipe, it will choose a different state according to the priority. Otherwise, it sets a two second timer and dashes towards the player's predicted position[2].

While in this state: The Router moves towards the player and attempts to throw a grenade every frame. Once it throws the grenade or gets within 50 units of the player, it will choose a different state according to the priority with a 0.1 second delay. If the two second timer expires, it gets blocked, or it leaves its allowed area, it will choose a different state according to the priority without delay.

Camp

Not to be confused with Camp (tactic).

The Router sets its target velocity to 0 and sets a timer based on its level. In practice this will always be two seconds. The Router then tries to throw a grenade to the player's predicted position every frame. Once the two second timer expires, it will choose a different state according to the priority.

Position for Runup

This behavior can only be exhibited by Defending Routers.

The Router picks a point 100 units away from the closest valid position to the player, sets a 1.5 second timer, and navigates towards the point. Once it reaches the point, it transitions to Snipe, but if the timer expires it will choose a different state according to the priority.

Aphid

Diagram of the Aphid icon.png Aphid AI

Aphid icon.png Aphids have six unique states. Only four are implemented.

Priority

Not seen in the priority list are Attack and Boost into Attack, which are transitioned to by other states.

Flee and Leave Tar

Upon entering: The Aphid tries to pick a point between 50 and 150 units behind it, away from the player. If the farthest it can reach is less than 50 units or there is no straight line between it and the point, it will choose a different state according to the priority. Otherwise, it sets a 2-3 second timer and a 1.5 second tar timer.

While in this state: The Aphid rotates its target point, relative to the player. The rotation direction has a 50% chance of being clockwise or counterclockwise. While the tar timer is counting, it will try to emit tar. Once the 2-3 second timer expires or something gets in the Aphids way, it will choose a different state according to the priority.

Approach for Attack

Upon entering: The Aphid picks a point in a 180° semicircle pointing at the player and sets a one second timer. If no point has line of sight with the player, the Aphid will check if it can already hit the player, and transition to Attack if it can, or Navigate to close range if it can't.

While in this state: The Aphid navigates towards its point. If it reaches the point and the player is within flamethrower range, the Aphid transitions to the Attack state. Once the timer expires, it has a 50% chance of transitioning to Attack if the player is within range, or re-entering this state to navigate again. If the AI level is 1 or more and the Aphid has less than 20% heat buildup, it will enter the Boost into Attack state.

Boost into Attack

This state cannot currently be seen in-game as no enemy has an AI level above 0.

Upon entering: The Aphid picks a point in a 180° semicircle pointing at the player. If no point has line of sight with the player, the Aphid will choose a different state according to the priority. If the Aphid doesn't have line of sight with the point, it will check if it can already hit the player, and transition to Attack if it can, or Navigate to close range if it can't. Then, it begins firing its flamethrower.

While in this state: The Aphid moves towards the player while facing away, causing it to boost. Once it's within 30 units of the target point or if it has too much heat but can hit the player, it will transition to Attack. If the Aphid's heat is over 90% it will choose a different state according to the priority.

Attack

The Aphid's target point is locked relative to the player, and it constantly aims at the player while attacking. While the player is in its allowed area, it walks towards the target point. If the player is out of range for more than one second, the Aphid will choose a different state according to the priority with a half-second delay. If the Aphid's heat is above 90%, it will immediately enter Flee and Leave Tar.

Deadlift

Diagram of the Deadlift icon.png Deadlift AI

Deadlift icon.png Deadlifts have ten unique states. Only seven are implemented.

Priority

Not seen in the priority list are Attack, Grapple Foe, and Juggle & Launch entity, which are transitioned to by other states.

Approach for Attack

Upon entering: The Deadlift will immediately enter the Attack state if it's within 50 units of the player. Then, if there is no unobstructed straight line between the Deadlift and player, it will enter the Navigate to close range state. Finally, it picks a point in a 180° semicircle pointing at the player if it is Rushing or you are within the area is controls. Camping Deadlifts will pick their current position. If no such point exists, it will move 100 units in your direction, clamped to the area it controls.

While in this state: After a second has passed or it reaches its destination, the Deadlift will choose a different state according to the priority if the line between it and the player is obstructed. If it is not obstructed, it has a 10% chance to Position for Grapple. If it doesn't and it is within 50 units of the player, it will enter the Attack state, otherwise trying again by re-entering this state.

Attack

Upon entering: The Deadlift sets a timer for between 0.3 and 0.8 seconds and begins charging a punch.

While in this state: The Deadlift will move towards the player. Once the timer expires, it will choose a different state according to the priority and go on a half second cooldown. This also causes the Deadlift to throw the punch.

Position for Grapple

A Deadlift icon.png Deadlift's 5 grapple positions

Upon entering: The Deadlift determines if the player is within grappling range and has line of sight. This is 130-200 units for Rushing Deadlifts and 50-200 units for any other tactic. If the player passes both checks, the Deadlift sets its state to Grapple Foe after 0.6 - AI level * 0.2 seconds. In practice, this is always 0.6 seconds. If this check doesn't pass, the Deadlift picks one of 5 points in a semi circle around the player at their preferred grapple range. If no such point exists, it will choose a different state according to the priority.

While in this state: Once the Deadlift reaches its point or 2 seconds have passed, it will enter the Grapple Foe state with a 0.3 - AI level * 0.2 second delay. In practice, this is always 0.3 seconds.

The Deadlift will not enter this state again for 2 seconds.

Grapple Foe

Upon entering: The Deadlift sets a timer for 1.5 seconds and launches its chain.

While in this state: The Deadlift checks if it has grappled an entity every frame. If it has, it will enter the Foe Grappled state. If 1.5 seconds have passed, the Deadlift will choose a different state according to the priority.

Foe Grappled

Upon entering: The Deadlift sets a timer for 2.0 - AI level * 0.5 seconds. In practice, this is always 2 seconds.

While in this state: The Deadlift starts circling the target. If the Deadlift is hit, it immediately retracts the grapple. When the timer reaches 0 the Deadlift will transition to Launch Entity or Juggle Entity depending on its level. The Deadlift will do this 0.5 seconds early if the target is more than 200 units away.

Juggle Entity

This state cannot currently be seen in-game as no enemy has an AI level above 0.

Upon entering: The Deadlift sets a timer for one second and begins tugging its chain.

While in this state: The Deadlift will release its grapple upon being hit or the timer reaching 0. When the target is within 50 units, it will throw an uncharged punch and re-enters the Juggle state once for every level it has. When it has juggled the target enough, it will enter the Launch Entity state as long as the target is alive. If the target is dead, the Deadlift will choose a different state according to the priority.

Launch Entity

Upon entering: The Deadlift sets a timer for one second and begins tugging its chain.

While in this state: The Deadlift will release its grapple upon being hit or the timer reaching 0. If the entity is killed before the Deadlift can launch it, the Deadlift will choose a different state according to the priority. When the target is within 50 units, it will release the punch it charged, then choose a different state according to the priority with a half second delay.

Upon exiting: The Deadlift retracts its grapple and stops tugging.

  1. Actually, it's if the full_auto flag is enabled. As of v0.4.3a, this is enabled for all Steeltoes when you have the Steeltoe Shotgun Full-Auto option enabled.
  2. 2.0 2.1 Due to a bug, Router icon.png Routers will always dash towards their aiming direction. This, for example, causes dashing away to be an awkward process as they usually dash toward the player rather than away.