- Home /
how to make objects only collide with some objects Unity c#
i have two balls each with a separete rigidbody bouncing around in a 2D space, and i want them to collide with everything except the other ball. how do i do that?
Answer by pako · Feb 25, 2018 at 01:52 PM
You can put the two balls in separate layers, and then in the Physics2DSettings "Layer Collision Matrix" disable interaction between the two layers (uncheck the checkbox):
Edit Menu/Project Settings/Tags and Layers
Expand the Layers section at the bottom
In two "User Layers" add: "BallLayer1" and "BallLayer2"
Edit Menu/Project Settings/Physics 2D
If necessary, expand the "Layer Collision Matrix"
"BallLayer1" and "BallLayer2" will be listed both along the top and on the left hand side
Identify where these two layers interest and uncheck the checkboxes
All other checkboxes should be checked
Assign "BallLayer1" and "BallLayer2" to Ball 1 and Ball2 respectively (top right in the Inspector of each ball)
That's it! The two balls will interact with everything else (normally in the Default Layer), except each other.
Your answer
Follow this Question
Related Questions
How to move rigidbody relative to a moving object? 0 Answers
Collision 2d is not working perfectly 0 Answers
How do you make a car drift in unity 2D 1 Answer
How do I add force to a RigidBody2D? 2 Answers