0
\$\begingroup\$

Does anyone know how to prevent a gameobject from colliding with another gameobject but can still register collisions? Like a ball that can bounce off of the wall or ground and can pass through the player himself.

What I have tried: Creating two Colliders on the ball(which has a rigidbody component) and making one of them bigger than the other (and turn on "Is Trigger" on the bigger collider). Then write code in the OnTriggerEnter and the OnTriggerExit functions to disable/enable the smaller collider so that the ball could fly right through the player. But that is completely useless when the ball is not in motion and the player walks over it(because it'll fall straight down through the ground).

\$\endgroup\$
2
  • \$\begingroup\$ You can try one collder and another trigger-collider. Then in the layers matrix set collder's layer to detect only layers you care about. Put them on 2 sepatate child game objects with each having its separate MonoBehaviour that handle collisions/triggers as you like. If you just want to pass through player then trigger-collider is not even needed. \$\endgroup\$
    – Nikaas
    Commented Aug 4, 2020 at 6:23
  • \$\begingroup\$ Thank you for your response, my problem's been solved:-) \$\endgroup\$ Commented Aug 4, 2020 at 9:01

1 Answer 1

2
\$\begingroup\$

You can configure the layer collision matrix in the Physics settings of your project so your gameobject in a particular layer interacts or not with other layers

You can find it in Edit > Project Settings > Physics

enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ Worth noting that this method of having certain collision types respond differently is industry standard when it comes to game engines \$\endgroup\$
    – Natalo77
    Commented Aug 4, 2020 at 8:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .