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.

Monday, November 11, 2019

Candles Update: Sin A.I. Part 1: Sin Sense

It's been 10 months since a Candles Update...but I have still been working. There's actually a fair amount to catch up on. Also, I've been doing updates on Tumblr.

(...not just because I work there...)

https://zachmakesgames.tumblr.com

So my plan for future posts is to be more focused and not just cramming every update into a single post.

The core gameplay of Candles is a ghost/demon/monster hunting the player. I did not seek or follow any stealth-gameplay guides created by others, but I peeked at a few to solve problems I faced. For the most part–I wanted to design the AI to meet my needs, and not fall in line with what someone else thought was necessary.

I cannot overstate how aggravating this process for Sin’s AI has been. I can say that it went through many iterations, weeks of stalling, and in the end–I learned many new things.

Step 1 (I decided) was giving Sin (my bad guy) senses. Enter my script “SinSense”.


image
This script is mostly made of booleans. It doesn’t do very much, but several scripts either make changes or track the changes to this script.

Outside of booleans, I only track whether the player is moving, if they’re sprinting, and are they close to Sin. Thus defining whether Sin can hear the player.


image
This script represents Sin’s FOV. I stole the FOV bit and added a ray cast. Basically it detects whether the player should be within a cone of view from Sin. If the player is within said cone, then it fires a ray cast to see if Sin can actually see the player. It then makes changes to the SinSense bools accordingly.


image
SinHearPlayer is a script that does a little more than SinSense. If the player is heard (while not having been heard recently) it attracts Sin’s attention: that is, it stops Sin from moving. Other scripts actually rotate Sin toward the sound.


image
That covers the “Sensing” part of Sin. Still missing, taste, smell, and and touch, I guess. But Sin’s not really a dinosaur, so I’m not sure those others are as important.