Shooting from inside colliders

Not sure if this will be handled later in the course or not, but I noticed that you can shoot from inside (or on the other side) of colliders such as trees and foreground tilemaps. From what I can figure, that is because the arrow spawn point is beyond the player’s body collider and so if you press against the foreground object, the arrow will spawn inside. So that means the OnTriggerEnter2D() event doesn’t fire.

How would you deal with that?

I had a couple ideas.

Could try to detect of the arrow in spawning inside a enemyHealth/indestructible trigger collider, but not sure if there is an easy/efficient way to do so? Do some sort of ray cast…?

Could add a collider to the spawn point and flag whether you’ve entered or exited a enemyHealth/indestructible trigger collider? Issue I could think of for that is if the spawn point enters overlapping colliders.

I feel like there ought to be a better method, but I guess that’s why I’m doing the course. Hopefully it’s taken care of in a later lesson.

Thanks.

IIRC it’s not. Colliders do not trigger when things spawn inside them. There is a project setting that you can set that will change this, but it’s off by default because of the performance impact. I believe it’s this one


Not 100% sure it will report a spawn inside a collider, but it will certainly prevent the arrow/projectile from leaving the collider

1 Like

Thanks for the info. I should one day go through all those physics settings. I’m sure there’s lots there that’s good to be aware of.

Privacy & Terms