80.8k views
1 vote
Think of an AI reaction you’d like to include in your Game On project (or a clever reaction in a game you admire) that could be coded with a listener and a trigger. The reaction doesn’t need to be complicated, but it should be something other than the basic “recognize when the player character approaches” trigger from the unit. Explain what the reaction is, what variables you’d need to establish that reaction, what states you’d need to establish, and the general script you’d have your AI follow. You can use “pseudocode” in your answer—text that resembles code but doesn’t require exact syntax or specific commands (for example, “transform y + 1” could be pseudocode for jumping).

User Aminta
by
8.0k points

1 Answer

2 votes

Step-by-step explanation:

One AI reaction that could be included in a Game On project is triggering the enemy to chase the player when they hear a gunshot.

Variables: gunshot sound, player position, enemy position, distance between player and enemy

States:

- Idle: Enemy is patrolling and not actively searching for the player.

- Alert: Enemy has heard a gunshot and is actively searching for the player.

- Chase: Enemy has located the player and is actively chasing them.

Script:

When a gunshot sound is played, the enemy's state changes from Idle to Alert.

If the player is within a certain distance of the enemy, the enemy's state changes from Alert to Chase and begins to move towards the player's position.

The enemy continues to chase the player until the player either moves out of range or the enemy catches and kills the player.

Pseudocode:

if gunshot sound is played:

enemy state = Alert

if player within certain distance:

enemy state = Chase

move towards player position

if distance between player and enemy < 1 meter:

kill player

else if distance between player and enemy > 10 meters:

enemy state = Idle

User Shibin Raju Mathew
by
8.6k points