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

Is it possible to have multiple PhysicsRaycasters on a Camera for different layers?

Discussion in 'Physics' started by azurvii, May 24, 2015.

  1. azurvii

    azurvii

    Joined:
    Mar 26, 2015
    Posts:
    5
    I'm trying to have events working on triggers with colliders in different layers, which are overlapping each other from camera.

    What I tried:
    * Attach 2 PhysicsRaycasters on a Camera
    * One uses UI mask
    * Another uses MyOwnMask mask
    I have 2 plane colliders in the world, one is for panning camera, in UI mask; another is for placing buildings, in MyOwnMask mask. They are geometrically the same plane, but may or may not be enabled at the same time.

    The problem I have is when they are both enabled, I can't get events triggered for both of them correctly. I.e. only one of them randomly got triggered.

    I guess the PhysicsRaycasters summarize the raycast hit results and pick only the closest one.
    Are there currently anyway to trigger events on overlapping objects?

    Thanks!
     
  2. andrew-lukasik

    andrew-lukasik

    Joined:
    Jan 31, 2013
    Posts:
    239
    EDIT: Ignore this post, I obviously messed up culling mask with physics

    Have you tried using two camera for that maybe? If camera's Culling Mask is set to single layer only (like MyOwnMask) it wont be obstructed by anything else.
     
    Last edited: May 26, 2015
  3. azurvii

    azurvii

    Joined:
    Mar 26, 2015
    Posts:
    5
    Thanks Andrew for taking time. Not sure if I misunderstand your meaning, but I think Culling Mask only affects rendering. Raycasts are in the collider world.

    What I ended up doing right now as a (hopefully temporary) solution was to remove the camera panning plane, and put that in a TouchInputManager, managed with Input class. So that the building placing plane could be freely used for events. (Use one PhysicsRaycaster)

    Another possible solution I come up with is to discard PhysicsRaycaster, but use Physics.Raycast in conjunction with GraphicsRaycaster to fine tune which layer to interact with, and connect those with home brew events. (Use no PhysicsRaycaster)

    But since EventSystem has much potential and is easy to configure, I prefer using them as much as possible.