Physics.ignorecollision is not working

Hi I have an issue with physics.ignorecollision. I want the player to not collide with the gun but I have to delete the rigidboyy when the player picks up the gun but it causes collision to register again upon rigidbody rebuild. So I put the ignore collision on update and now it’s still not working…

Does the player ever need to collider with the gun? I suspect not and if so then you can just edit the layers to ignore the collisions. To do that:

(On Windows go to the menu options at the top)
Edit/Project Settings/Physics

Then you can see all the layers that can collide with each other. Make one for your gun, or a generic layer for the player to ignore, and make sure its checkbox is unchecked against the player and they will never collide.

As an FYI deleting and rebuilding a rigidbody will be pretty slow.

BTW if my method doesnt encompass what you need then I suggest making a layer for pickups, have your gun on that layer when it needs picked up then change its layer to one that the player ignores once it is picked up and it should work without you having to hack with deleting and creating rigidbodies

Hate to revive such an old question; but I’m actually having this issue right now. When my character holsters his gun, it moves his whole body because there is a part of the animation where part of the collider of the gun moves outside his body.

The gun has a collider set to isTrigger (originally it was box collider, I tried mesh collider too)

I was using Physics.IgnoreCollision on my inventory script, I even tried putting it before and after the crouching function on my movement script because that changes the character height.

I tried putting the ground on a separate layer and turning off collision between the player layer and everything else but the ground layer.

Nothing works, it actually is extremely frustrating :frowning: