Project: MouseyScare – Detecting a ghost
(2017/08/16)

I suppose this little entry will be about my biggest complaint with FPS Horror / Scary Games. I see a lot of developers who use hitbox detection for jump scares and while that’s okay for some things, it shouldn’t be the sole factor in scaring a player. Another issue is when players are looking someplace else completely and completely miss a ‘timed’ scare, all they hear is the audio cue and go “Huh? What did I miss?”. Seriously, I’ve seen so many Let’s Plays that have this problem. Property ‘entity’ detecting is important and severely underused.

One day I decided figure out an option to rectify this, and this is a technology I will be using for Project: MouseyScare.

Detecting a Ghost!

To start, I took a flashlight with a spotlight and added an invisible cone collider that matched the diameter of the light beam. This would allow me to detect if the cone collided with any object that was a ‘ghost’.  This is a great place to begin but it didn’t give me any real data.  If I used this method alone then it would collide with a ‘ghost’ that was behind a wall or with a ‘ghost’ that was on the very edge of my vision.  Not enough for a scare.

To remedy this, I wrote a little script. It has a few public variables, such as the ghost layer, the light distance, and a ‘threshold’.   It casts a ray out from the center of the flashlight once it detects that a ‘ghost’ object is being viewed. This line will stop when it collides with _ANYTHING_. Then, it calculates the closest point on that line to the ‘ghost’ and measures the distance of that point to the ‘ghost’ itself.  This allows me be sure of multiple things:

  • The ‘ghost’ isn’t in a different room and we can actually see it.
  • How directly a player is looking at a ‘ghost’
  • How long they look at the ‘ghost’
  • And if/when they look away from a ‘ghost’.

Of course, in all of this, I don’t have to check for the ‘ghost’, I can check for specific objects instead, and use the same data to trigger an event.  Say, if I wanted a scare to happen after the player looked at a poster, or an object on the floor.

Below are two screenshots: One that shows the players view down a prototype hallway where the ‘ghost’ is a box. The other shows the debug side of things, where you can see the ray cast and two spheres that represent the first wall hit and the closest point to the ‘ghost’.

 

Light shining on a box down a hallway.

 

Showing line of sight collision orbs and orbs to show line of sight hitboxing.

Leave a comment

Your email address will not be published. Required fields are marked *