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.
Update, the modern way to turn the trigger off is: GetComponent().isTrigger = false Just wanted to help for those who end up here looking for a modern solution. This worked for me. This was the easiest way to handle the collisions without discreet logic for types. My use was not the object spawning, so this worked.
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.
Yes, I know how to handle code, problem is that the engine will stop the bullet from "flying" as it literally hit the player. I spawn a bullet add a force and then it immediately get stopped as it hits the player who shot it. Hence I need it to ignore the player collision and fly through the player who shot it.
The trigger trick worked excellent for me. Thank you so much
– LeeEppUpdate, the modern way to turn the trigger off is: GetComponent().isTrigger = false Just wanted to help for those who end up here looking for a modern solution. This worked for me. This was the easiest way to handle the collisions without discreet logic for types. My use was not the object spawning, so this worked.
– xxmark71xx