- Home /
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...
Answer by LaireonGames · Feb 22, 2015 at 08:24 PM
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
And what if I need my guns to be ignore ray cast? I can't assign them another layer...
I'm not really sure what to say.. you haven't said anything I can reply to!
And what if I need my guns to be ignore ray cast? I can't assign them another layer...
You can switch the layer of your gun as needed, since as you say it can't be more than one layer at once but it also should never need to be.
I also don't see why it would have to be ignore raycast since what I explained above is a way of making any layer ignore collisions from any other layer.
If you are doing raycasting yourself again you can ignore your custom layer by telling the RayCast function which layers to check
But I'm using onmousedown so it's built in. What do I do so that the cursor ignores a user layer?
Answer by Sungold · Aug 03, 2017 at 04:32 PM
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 :(