This question has been bothering me for some time, im curious as to what the “standard” solution is.
So for example, let’s say i have a 2D turret sprite with a circle2D collider.
When i shoot it instantiates a 2D bullet sprite rigidbody prefab with box2d collider and applies a one time addforce to it. Nice and simple.
BUT unless i move the bullet spawn point to the outside of the turret collider2d, the bullet will collide once with the turret collider. Generally if i move the spawn point reasonably far from the center of the turret collider, the bullet wont really divert course or lose any speed. The closer i bring the spawn point into the turret, the more of a chance that spawning a bullet will make it fly off at an angle or get completely stuck inside the turret collider.
Now i know you can set the collision layers of the bullet and turret to ignore each other and that would solve EVERYTHING.
What if im making a game where i want the ability of a bullet to damage friendly turrets, and setting the layers to ignore each other would mess that up.
I thought of maybe a TIMED collision layer enable script that would wait for the bullet to exit the turret completely before enabling collision with turrets, BUT what if theres another friendly turret so close to the one that’s shooting so that the bullet comes into contact with it before fully leaving the turret that shot it!?
it all just seems very inelegant… although is it possible to make the bullet ignore ONLY the turret that shot it until its completely outside? and then reenable collision with it?
Also technically, even if there was a turret right near the one that’s shooting, bullets generally travel fast so it won’t even be noticeable that the bullet didnt collide with the turret until it was already inside it because collisions didnt activate yet.