Search Unity

Resolved collision stay

Discussion in 'Scripting' started by PlayerCasual, Mar 19, 2023.

  1. PlayerCasual

    PlayerCasual

    Joined:
    Jan 3, 2023
    Posts:
    274
    hi to all!!
    for programming needs I can not change the layer of this object ... it is a stone that the player can destroy, some enemies change direction if they collide and others that should pass through .... Now.. how do i allow an enemy to pass through???

    whit this not is possible
    Code (CSharp):
    1.  Physics2D.IgnoreLayerCollision(12, 12);
    because the object is on the ground so if i change layer the object will fall through the floor the code i showed "12,12" it's the enemies layer because they have to cross each other

    so i was thinking of using this code
    Code (CSharp):
    1. private void OnCollisionStay2D(Collision2D stay)
    2.     {
    3.         if (stay.gameObject.name == "Smallrock")
    4.         {
    5.            
    6.         }
    7.     }
    but I noted with disappointment that I don't have an "ignore collision with this object" or similar command Could you please help me how can i do this??? thank you in advance
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,049
    Why can't you have 1 layer for the default and 1 layer where everything can pass through?
    Then you only need to switch the layer without touching physics in code
     
  3. PlayerCasual

    PlayerCasual

    Joined:
    Jan 3, 2023
    Posts:
    274
    because if I change its level when the player walks over it it won't detect it... and it will stay with the jump animation... the object is now on the ground
     
  4. PlayerCasual

    PlayerCasual

    Joined:
    Jan 3, 2023
    Posts:
    274
    i solved...
    just create another check for layer in player movement