Tutorial 3 - AI chase
Tutorial 3 - AI chase
For this tutorial work I've learned how to set up an environment that allows NPCs to navigate their way around a location.
The first step is establishing the Navmesh or Navigation Mesh, which acts as a 3 dimensional map for the AI to be bound by. Unity handles most of this on its own. Below is a before and after, where in the after picture, a navmesh has been laid down over the existing geometry.
There are extra settings like allowing the AI to jump gaps or drop from a height, but I've kept things simple here.
The AI characters themselves are known as 'agents' within Unity, and there are settings that determine the width and height of an agent in the game world, as well as their ability to climb steep slopes or steps.
Creating followers
Once you've established the rules of the navmesh and abilities of the agent, it's possible to drop an agent into the world, tell it where to walk, and it will find a suitable path towards its destination. In this case, I've set up a script that allows you to click somewhere to spawn an NPC, and they will direct themselves towards the player character at all times. The NPCs make use of the same code that animates the player, ensuring they have a walk cycle at the correct pacing for their movement speed.
From here you would likely make them attack the player when they get near (if you were coding enemies), but for this tutorial they are just loyal followers.
KIT207 Portfolio
Status | In development |
Category | Other |
Author | Flynn Delta |
More posts
- Tutorial 5 - Post-processing & CinemachineAug 28, 2023
- Self Study 4 - Simple gameAug 26, 2023
- Self Study 3 - Terrain and ProBuilderAug 09, 2023
- Ideas Self StudyAug 08, 2023
- Tutorial 2 - Walking in UnityAug 05, 2023
- Self Study 2 - AnimationJul 25, 2023
- Tutorial 1Jul 21, 2023
- Self-study 1Jul 21, 2023
Leave a comment
Log in with itch.io to leave a comment.