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\$
  • \$\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 Aug 4 at 6:23
  • \$\begingroup\$ Thank you for your response, my problem's been solved:-) \$\endgroup\$ – MetaMax Aug 4 at 9:01
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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.