Conceptualizing stealth

Godot Version

4.2.2

Question

Hey, guys!

Ray here.
Right now I’m in the process of mostly conceptualizing my game. Plus, I’m teaching myself coding through tutorials, I give myself half a year before I feel comfortable making my game. Anywoo… I want to make a stealth name. 2D. I have the original Metal Gear Solid in mind. Right now I’m going through a bunch of tutorials to get a sense how I’m going to implement anything.

As for stealth detection, what would any of you say would be the best means to go about it? Raycast? Area? I want the cone of field you see in MGS, Raycast seem to be a bunch of lines , and I saw one tutorial that had a dozen to create a radius line of sight with no blind spots. That to me didn’t seem to be the most optimal route to go. Areas are good for aggro ranges (WoW term) but supposedly they can’t not see through walls, and will go past LOS.

So, what would you guys say would be a good way to go about it?

1 Like

there’s ShapeCast2D

For line of sight, I’ve had success with this technique:

  1. Use an Area to detect when the player is close enough to see (and use collision layers to avoid checking a bunch of irrelevant objects), OR just keep a reference to the player and use the distance_to function to check if they’re close enough (this works well if the player is the only thing the NPC needs to detect).
  2. When the player is in range, calculate whether they’re inside the view cone as well (this is just math)
  3. If the player is in the view cone, do a raycast from the NPC to the player, to see if there are any walls in the way

You can also use an area for hearing range, if that’s something you want.

1 Like

I personally haven’t used it, but maybe this?

https://godotengine.org/asset-library/asset/1568

1 Like

Cool, thank you, I’ll look into all these responses.

I like to know every technique just to know what would be the best route. :+1: