I have a situation which probably many others have faced, I got a player, that player has a rigidbody and collision, this player shoots from a weapon bullets which have rigidbody and collisions as well. These bullets are meant to hit other players.
This all sounds pretty simple, but problem is, that given that I spawn the bullets in a middle of transform of the player who shoots, they immediately collide with the player who shot them out. I would like to make the bullets ignore the collision of their owner (the player who shot them).
How can I do that?
P.S. Some of you might suggest “why spawn them in a middle of player?” That is related to another question I made How to calculate position where bullet should be spawned - Unity Answers the answer is, that it’s not that simple to spawn them anywhere else in order to achieve this what I need.
As soon as you instantiate the bullet, call the Physics.IgnoreCollision and pass the 2 colliders (the collider of the bullet itself and the collider of the player). So the collisions between the 2 colliders will be ignored and therefore the bullet will pass through the player’s collider.
Well, in general your player can collide with pretty much anything (not only bullets), so the best way is to only perform code on specific bullets. You have the Collision parameter for this.