Reputation: 329
(I saw a question like mine, but my case is different)
I explain:
I have a 2d game(side view), where players going around and hit each other with weapons like sword or hammer. I set ground on a collision layer called "Ground" and players In "Player" layer. and the collision of the "Ground" and "Player" layer is checked. the ground has no rigid body but the players have(due to using gravity and etc). I want players don't collide with each other to have a smoother mechanic but I want to detect and receive messages when they pass through each other, for some porpuses that I need. Now, if I uncheck the "player" collision layer (In Collision2D settings) they can path through but I can't receive any messages due to Inactive collisions. and if I set the player's collider as trigger they pass through ground and fall. (please correct me if I'm wrong)
so what can I do?
Upvotes: 1
Views: 10099
Reputation: 329
So after playing with what the Toaster said, I find the solution.
The ground collider must be in layer "Ground", the player with a collider with trigger checked in "Player" Layer, and we also need a third layer called for example "GroundCollider" and a child object for the player with a collider with trigger unchecked.
Ok. then in physics 2D settings "player" layer must check collision JUST with itself. and "Ground" layer and "GroundCollider" should check collision just with each other, not with itself or with any other layer.
with these settings, the player collides with ground and two players can check collision with each other and also can pass through each other.
Upvotes: 0
Reputation: 15941
If both objects need to be solid (not trigger volumes) then you need to edit the physics layers.
This just happens to be from a project I'm working on, the layers at the top with red marks next to them are the default ones. At the bottom is "edit layers" where you can name and define new layers (up to 32 total).
Uncheck any pair that should not collide (by default all layers collide with all layers).
Upvotes: 4
Reputation: 4110
Have your player game object have two children objects (one that you could call GroundCollider, on the you could call PlayerCollider)
On the first one, add a collider with onTrigger unchecked. On the second one, add a collider with onTrigger checked
Upvotes: 2