How to detect nearby environement ?

Hi,

I am working on a small tactical game and I seek your advices to handle the stealth system.
My map is divided into bare plains, tall grass areas and dense forests, and the player speed is altered by the type of environement he is currently in. What is the best way to detect his surrounding environement ?

  • Shoud I add an invisible circular mesh at the base of all my environement prefabs and use it to trigger a collider on the player object ?
  • Should I list all his surrounding objects with an OverlapSphere (Unity - Scripting API: Physics.OverlapSphere) ?
  • Better ways ?

Thank you very much!

Hi,

You can use the same solution as in here: Changing Footstep Sound When On Different Surface? - Questions & Answers - Unity Discussions

But instead of modifying the sound, you will change the speed !

Edit: 1. Keep in mind that if you’re developing for mobile, raycast can be heavy, especially at each frame, consider InvokeRepeating(), coroutine, …
2. Instead of checking the tag, i’d check the material directly (Renderer.Material) so you can also use the tag in an other script (like if you have moving plateforms, highground, lowground, …)