- Home /
Ignore collision before instantiating
I am trying to instantiate a bullet which fires from the center of my 2D character. The bullet is colliding with the player that fired it because it spawns before I can call IgnoreCollision. It can't be a trigger because I need it to bounce off walls. I can't ignore layers because I want the bullet to collide with other players. Any ideas?
Can you move the instantiate point to be a little bit out front of the character, thus missing the collider?
Add a bullet spawn point gameObject on your player, then just use that to instantiate your bullet. It's essentially a spawn point or socket.
I'd rather spawn from the center of my character for right now. I need to be able to tell the object that I don't want it to collide with the player that fired it before I instantiate it.
Answer by Vega4Life · Dec 07, 2018 at 12:10 AM
I just ran a test with this:
if(Input.GetKeyDown(KeyCode.Space))
{
Bullet bullet = Instantiate(bulletPrefab, transform.position, transform.rotation);
Collider bulletCollider = bullet.GetComponent<Collider>();
Physics.IgnoreCollision(spawnerCollider, bulletCollider);
}
It spawns inside of the spawner, doesn't move, doesn't call OnCollision events. So, not sure whats going on with yours.
Hm, that is pretty much exactly what I am doing. I just tried out my layer for each player and each player's bullets idea and that seems to be working just fine, just a bit messy I guess.
@Vega4Life changed your comment to an answer.
Your answer
Follow this Question
Related Questions
Updated Unity, 2D Colliders not working. OnTriggerEnter2D not working 0 Answers
Is Overlap Circle Supposed to return inactive colliders? 1 Answer
Bullets go through collider even with continuous collision detection! 0 Answers
Collision with instantiated non-moving objects. 1 Answer
Edge Collider issue 1 Answer