- Home /
The question is answered, right answer was accepted
Object: collider to floor, trigger to player
I want to create an enemy in a 2d setting, the player should be able to walk past it, but the enemy should not fall through the floor, the floor has a floor tag and the enemy and player has their own tags to, I am fairly new to coding so I dont know how to do this exactly
yeah, now I can detect when the player collides with an anemmy, how do I make the player so he can walk past that enemy without making the enemy a trigger? because if I make the enemy a trigger, he falls through the ground (sorry if I have bad english)
I think you should have a look at the unity collision layer: here. You can set layer1 to the floor. At your floor object you tick all layers. So all object collides with the floor. Then you set the enemy to layer2 and the player to layer3. At the enemy tick layer2 and at the player tick layer3. So all player prefabs collide with themself. And all enemys with themself. But the enemy does not collide with the player, because the player is on layer3, which the enemy don't check... I hope you understood that. (Your english is good to understand -- I'm from Germany ;-)
Answer by Varniukas · Feb 22, 2021 at 01:14 PM
You can ignore collisions like so :)
layer 0 (default) and layer 8 (custom layer you set in Inspector window)
Physics.IgnoreLayerCollision(0, 8);
another approach
Physics2D.IgnoreCollision(target.GetComponent<Collider2D>(), GetComponent<Collider2D>());