Search Unity

Ray 3D Sensor Detects Ghost Objects ? - How Debug

Discussion in 'ML-Agents' started by JulesVerny, Feb 26, 2022.

  1. JulesVerny

    JulesVerny

    Joined:
    Dec 21, 2015
    Posts:
    47
    I have a ML Agents using a 3D Ray Sensors. I have it tagged to select just a few specific Tagged Game Objects (Colliders).
    But my Ray Sensors are picking up some objects, that I have not created. See the Image below.
    RayDetectGhostObjects.PNG

    The Sensor is picking up some invisible object to the Left of my Character. (The Rays are all horizontal, they are not hitting the ground plane.)

    It is not obvious How I debug why and what this 3d Ray is intercepting. I switch on/off my intended GameObject colliders, to confirm that is has noting to do with my intended Game Objects
     
  2. ChillX

    ChillX

    Joined:
    Jun 16, 2016
    Posts:
    145
    Use Layers:

    Put the objects you want detected on a Layer of their own. Then select that layer in the ray perception sensors layer mask.

    A ray cast does not care what object you want to detect. It will collide with the first collider it hits that is within the constraints of its layer mask.
     
  3. JulesVerny

    JulesVerny

    Joined:
    Dec 21, 2015
    Posts:
    47
    Ah OK, yes I need to be more precise with my collider management, and make use of Layers.
    I have been rather lazy.
    Thanks
     
  4. ChillX

    ChillX

    Joined:
    Jun 16, 2016
    Posts:
    145
    By the way your prisoner escape project is looking real good :)

    Yeah without using layer masks anything and everything that has a collider on it are going to block the objects that you actually want to detect.
     
  5. JulesVerny

    JulesVerny

    Joined:
    Dec 21, 2015
    Posts:
    47
    Yeah Thanks. I got my Prisoner Agents to Train Reasonably well, despite those ghost objects still being detected by my agents ray casts. There are really no Game Objects or colliders there. But in any case I will take your advice on my next Game/Project, to correctly use Layers t manage colliders
     
  6. ChillX

    ChillX

    Joined:
    Jun 16, 2016
    Posts:
    145
    If you really want to get to the bottom of it. You could add a script to the agent to do a series of manual raycasts from the agents position and add the detected game objects into a list variable.

    Kind of like:
    [SerializeField]
    Private List<GameObject> DetectedStuff = new List<GameObject>();

    Then in for each of your raycasts (have a bunch of them ideally matching the raycast sensor)

    for each (Collider Col in RayHit.Colliders)
    {
    DetectedStuff.Add(Col.hameObject();
    }

    Then to make it Unique again.

    DetectedStuff = new List<GameObject>(new HashSet<GameObject>(DetectedStuff));

    Let them run around and see game objects it picks up.