Search Unity

Really lost on whats going on here

Discussion in 'Physics' started by Shadowing, Feb 9, 2019.

  1. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,648
    My character is at the bottom of a lake.
    I"m casting a ray to hit the bottom of the terrain. This works no issue.
    Then I'm taking that point and casting it back up to hit a box collier on the surface of the water.
    It never hits the layer 4.
    The surface water collider is a Trigger.

    My debug ray points just how the ray cast should.
    If I remove the Layer Mask the raycast will hit my character as expected it would.

    So idk what I'm doing wrong.
    Unity 2018.3.4

    Code (csharp):
    1.  
    2.  
    3.             if (Physics.Raycast(SwimDetector.position, -m_Transform.up, out RaycastHit m_RaycastTerrainHit, Mathf.Infinity, LayerManager.Mask.IgnoreInvisibleLayersPlayer)) {
    4.  
    5.                             Debug.DrawRay(m_RaycastTerrainHit.point, m_Transform.up * 100, Color.yellow);
    6.  
    7.                 int layerMask = 1 << 4;
    8.  
    9.                 if(Physics.Raycast(m_RaycastTerrainHit.point, m_Transform.up, out RaycastHit m_RaycastWaterHit, Mathf.Infinity, layerMask,QueryTriggerInteraction.Collide)){
    10.  
    11.  
    12. // this never hits anything
    13.  
    14.                     return m_RaycastWaterHit.distance - m_RaycastTerrainHit.distance > m_SwimDepth;
    15.                 }
    16.             }
    17.  
    18.  
     
  2. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,648
    Nevermind I guess it does work :)
     
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    edit -> physics -> Queries Hit Triggers = true

    might be it?