Search Unity

Bug Boxcast triggering triggers

Discussion in 'Physics' started by MadXVH, May 25, 2023.

  1. MadXVH

    MadXVH

    Joined:
    Feb 16, 2023
    Posts:
    2
    I have this player and it uses a box-cast,
    In order to check if there's ground beneath it.

    But, it triggers the trigger when the player isn't actually in the area.
    If I have a problem with the code here it is.
    Code (CSharp):
    1.     private bool IsGroundedToFloor()
    2.     {
    3.         return Physics2D.BoxCast(coll.bounds.center, coll.bounds.size, 0f, Vector2.down, .1f, jumpableGround);
    4.     }
    This is the code that checks whether or not the player has contact with the floor.
    And here's the code to check whether the player is touching the trigger:

    Code (CSharp):
    1.     private void OnTriggerEnter2D(Collider2D collision)
    2.     {
    3.         logic.collisionNormal = true;
    4.     }
    5.  
    6.     private void OnTriggerExit2D(Collider2D collision)
    7.     {
    8.         logic.collisionNormal = false;
    9.     }
    Which detects when the player is in the area and when it leaves.
    So, is there a checkbox or different way/way to fix,
    The code so that it doesn't trigger the trigger?
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,492
    A query doesn't cause a trigger callback so I'm really not following what you're asking here. A query is a read-only operation, it doesn't change anything.
     
    arkano22 likes this.