- Home /
How to prevent object collision with its spawner
I have an bullet which can hit enemy as well as player. So if player spawns bullet it shoudnt collide with player but hit enemy and vice versa. Is there anyway to make this happen without use of layers.
Answer by Stratosome · Jul 15, 2018 at 10:35 AM
Hiya,
Well, without layers, you can use Physics.IgnoreCollision(). Given two colliders, it will make the two ignore each other. If the player is made up of multiple colliders though, you'd have to call this for each one which wouldn't be all that bad:
Collider[] playerColliders = player.GetComponents<Collider>();
playerColliders bulletCollider = bullet.GetComponent<Collider>();
// Make the bullet ignore all of the player's colliders
foreach (Collider c in playerColliders) {
Physics.IgnoreCollision(bulletCollider, c, true);
}
Something like that at least.
Your answer

Follow this Question
Related Questions
How to go about having two seperate Game Objects follow eachother? 1 Answer
How can I stop a rigidbody (Ragdoll) character from colliding with the Character Controller capsule? 1 Answer
jerks in gameplay of doodlejump like game 1 Answer
Script that activates all objects in layer on collision not working 2 Answers
How to achieve this basic physics effect? Detect when to change layers 2 Answers