Navmesh and AI
The task was to generate a navmesh for an existing level and create some basic AI that will path around the level chasing the player.
First step was obviously to generate the navmesh. Unity makes this very easy with the inbuild navmeshing functionality. All the parameters were left default aside from all static objects having the "Navigation static" object option selected.
Once that was done, I generated (baked) the navmesh and after a couple small adjustments, it was done.
I also added a block that moves back and forth as a non-static nav object for the AI to dynamically path around as it moved. I wrote a simple script to make it move back and forth.
It also had a Navmesh Obstacle component on it as well, which had the settings left at default.
I then had to write a script to spawn enemies and have them chase the player.
This was super simple. First I wrote a function to instantiate the enemy game object on a predetermined position. Once that was done, a single line of code was put in to the start function that just targets the navmesh agent and assigns that to the agent variable. Then in the update function it was time to write the AI "steering" behaviours. First I stored the player's current position as a variable. Then, if the player clicks on the screen, store that Vector3 location data as a variable and feed that into the spawn function. Then set the agent's destination as the player's current position.
The only downside of this function is that there is a slight delay (about 5 ticks) between the playerPos vector data and the player's ACTUAL position in-game. But I don't think that's a very big deal so I just left it.
And thats it! The finished result is almost like a zombie game, where the enemies try to overwhelm the player with their sheer numbers!
UTAS KIT207 Portfolio
My university portfolio for 2022
Status | In development |
Category | Other |
Author | Sevensz |
More posts
- Lighting and MaterialsAug 19, 2022
- Self-Study 4Aug 09, 2022
- Game brainstormingAug 09, 2022
- Self-Study 3 MoonscapeAug 07, 2022
- Character movement and animationJul 30, 2022
- First Animation PracticeJul 24, 2022
- Mercedes GLC RenderJul 23, 2022
- Moonah Giant Bowling Pin ModelJul 19, 2022
Leave a comment
Log in with itch.io to leave a comment.