Post 10: AI; Part 1
So I decided to start getting into some of the cooler stuff (well I think it’s cooler). The first on the list was a little foray into creating a bit of NPC AI.
The first step was figuring out how to implement the movement and have the ability to call on it. What I ended up doing was creating a master moveable character that would serve as the parent of the player and all other NPCs. All I really had to do to prep was to take the Camera and Spring Arm off.
I created an AI class that would contain all of the NPC logic.
I then placed a Nav Mesh into the level, with a pretty wide span and put a Nav Invoker into the NPC child that would act as a localiser of the Nav calculations. There are a couple of options in the project settings that I changed in order to make this work too:
- Nav Mesh / Runtime / Runtime Generation —–> Dynamic
- Nav Mesh / Runtime / Observed Paths Interval ——-> 0.5
- Navigation System / Navigation Enforcing / Generate Navigation Only Around Navigation Invokers ——–> True
- Navigation System / Navigation System / Auto Create Navigation Data ——> True
At this point, I thought I would implement a basic function that would get the NPC to run towards the character. This could be handy for attacking cycles, attention grabs and cinematics.
In the AI Class, I put in a basic location function that would get the location of the player, the location of the NPC, average them out (to find the direction) and then send the NPC on that path.
All in all, this turned out as well as I could hope for, seeing as this is pretty new to me.