Developing AI for First Person Video Games with Unity: Project PAC 1
In this entry, I share the development experience of the AI PAC 1 for first-person video games , where I worked on the creation of a scenario with autonomous agents using Unity and its Visual Scripting system . This project was my first contact both with Visual Scripting and with the creation of AI for characters in a 3D environment. If you are interested in the development of artificial intelligence for video games, this article summarizes the main stages and challenges of the project.
1. Creation of the Scenario
To begin, I built the scenario using ProBuilder , a Unity tool that allows you to graybox the level quickly and easily. This made it easier for me to establish the base of the environment and visualize the movements of the agents on the map. He chooses to use a camera with orthographic perspective that shows the whole level, as well as adding a script that hides certain objects to highlight the movements of the agents.
Why not a first-person view? Although the title of the practice suggests a first-person game, a playable character was not necessary at this stage, so I considered that this perspective would be more practical for the exercise.
2. The Ghost Agent
The ghost agent was the first autonomous agent I implemented. I used Visual Scripting (formerly known as Bolt) to program a random behavior that would allow it to move naturally around the map. Some of its features include:
- Random Wandering: The ghost moves randomly, pausing with a 35% chance to give it a more realistic effect.
- Return to the Center: To prevent the ghost from being blocked in the corners of the map, I added a code that detects the distance to the edges. If it gets too close, it redirects its movement towards the center.
3. The Security Agent
For the security agent , I implemented a state machine that controls the transitions between patrolling and fleeing. This agent constantly patrols the map and, if it detects the ghost in a certain radius, it goes into flight mode. Its main functionalities are:
- Patrullaje (Patrolling): The agent follows a fixed route and pauses at each patrol point to simulate animation changes.
- Fleeing: If the ghost enters its radius, the agent creates a vector in the opposite direction to the ghost to flee quickly.
- Transition between states: If the agent manages to escape the ghost, he resumes his patrol at the closest point on his route, thus avoiding returning to the danger area.
Final Reflections
This project has allowed me to familiarize myself with tools such as ProBuilder and Visual Scripting, as well as exploring AI concepts for video games. The help of ChatGPT has been fundamental to resolve doubts and structure the workflow with Visual Scripting, especially in the implementation of nodes and state machines. This experience has been a great introduction to the development of AI in video games and motivates me to continue developing my skills in this field.
Webography
- ProBuilder in Unity – Official Guide
- NavMesh tutorial in Unity by Brackeys
- Unity Visual Scripting Tutorial