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 Detect the Number of times a raycast intersects a Mesh

Discussion in 'Scripting' started by Lexo18, May 11, 2015.

  1. Lexo18

    Lexo18

    Joined:
    May 12, 2013
    Posts:
    34
    As the title asks I need a way to use the even-odd rule algorithm and as far as I am aware raycasts in unity only allow one collision per mesh and i need a way to detect whether the player is inside a specific mesh.
     
  2. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    968
    Wouldn't it be better to use OnTriggerEnter/Stay/Exit for this?
     
  3. Lexo18

    Lexo18

    Joined:
    May 12, 2013
    Posts:
    34
    would OnTriggerStay work if the object is fully inside the collider and not touching the "skin" of it?
    and i would personally like to learn how to implement the algorithim into unity
     
  4. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    968
    Yes, OnTriggerStay gets called whenever two triggers intersect, this includes when one is fully inside another.

    If you want do do it with raycasts, I think you can just cast a new ray from the hit point (plus a little offset).
     
  5. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
    You could also do the triangle ray intersection test yourself.
     
  6. Lexo18

    Lexo18

    Joined:
    May 12, 2013
    Posts:
    34
    What is the triangle ray intersection test? When i Google it I get examples in code and jargon I cannot understand.
     
  7. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906