Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to determine if a point is in Open Air or in water?

Discussion in 'Physics' started by UnityNoob91, May 31, 2015.

  1. UnityNoob91

    UnityNoob91

    Joined:
    May 31, 2015
    Posts:
    3
    How would I determine if a given Vector3 is in the open, i.e. not in any object or collider?

    Also is there anyway to determine if a given Vector3 is in water?

    Thanks for any help and /or consideration,

    Noob
     
  2. Eudaimonium

    Eudaimonium

    Joined:
    Dec 22, 2013
    Posts:
    131
    For water, easy, simply check the Y component and see if it's lower than your water level height.

    I'm not sure about checking whether a 3D point (Vector3) is within a collider, but you definitely cannot check if it's within any arbitrary object.

    Why do you need to check Vector3 against colliders, specifically? Perhaps you're going the wrong way about the problem.
     
    UnityNoob91 likes this.
  3. UnityNoob91

    UnityNoob91

    Joined:
    May 31, 2015
    Posts:
    3
    I want to spawn an object.

    I want to make sure I avoid water and that I dont spawn it within another object.
     
  4. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    I think you can use the Physics.CheckSphere method to see if it is in a collider or if a collider is in it.
    This only returns a true or false.
    If you want to check for certain colliders, you can use Physics.OverlapSphere. This will give you all the colliders that are inside or outside the overlapshere and you can then check their name, tag, etc...
     
    UnityNoob91 likes this.
  5. UnityNoob91

    UnityNoob91

    Joined:
    May 31, 2015
    Posts:
    3
    I will try that.

    Thanks!