Navigate

Tuesday, November 26, 2019

Candles: Sin AI (Part 2): NavMesh'n Around

Previously, I shared how Sin sensed the player. Now I want to cover how Sin gets around. It’s fairly straight forward: I use a NavMesh and NavMeshAgent – which is all built into Unity (so my work is done). What’s not so simple is behavior. To imply behavior, I need Sin to patrol, respond to sounds, chase the player, and investigate last known locations.

To simplify things, I’ve given Sin only one target–aptly named “Sin Target”.
image
Whenever I want Sin to go somewhere, I simply move his target to that location.

So–if the Sin can see the player, Sin Target’s position becomes equal to the player’s position. Now Sin appears to chase the player, when really, he’s just chasing the same target toward which he’s always moving.

But it’s also handy when dealing with Sin’s Patrols:

In every room there is an empty object named after the room it’s placed in. I’ve put these all in a list, kept on Sin. They’re separated by floor.
image
When Sin reaches a destination–the Sin Patrol script randomly chooses a new destination from the list. But, it is based on what floor the player is on. This keeps Sin relatively close.
image

I’ve considered creating routes for Sin–but we’ll see if it’s needed.

Bonus topic: Sin Opens Doors

There are lots of doors that the player can open and close. We can’t have Sin just passing through like a ghost, even though…he is…But then, why not just have him walk through walls?

Anyway, I created a simple script to allow Sin to open doors when he tries to pass through them.
image
image
One of the little details I didn’t think of at first, I have to tell the doors that Sin is nearby–otherwise the player can shut the door on Sin’s face. And then Sin would appear to walk through it. So the line “openThisDoor.sinHere = true;” helps with that.

Next–I’ll share Sin’s Brain.

No comments:

Post a Comment