Hi! I just found out a problem with my game, I’ve created an enemy that “fly’s by” the screen in order to hurt the player, but the problem is that the enemy moves to fast so that the collider doesn’t interact.
How can I fix this so that the enemy will take damage to the player no matter how fast it is going? Or well how fast it is currently going?
You can set the collision detection mode to one of the Continuous values. One thing to note from the documentation:
This has a big impact on physics performance,
The physics engine must do a lot more math for this so use it judiciously.
What @cherno says is probably the best solution. There was a deep discussion a few years ago about how discrete and continuous detection have almost no difference in accuracy, when detecting fast moving objects. So don’t bother.
I’d suggest to forget about the
collision modes, you’ll never make
them 100% reliable for fast-moving
objects. Instead, raycast from the
last frame’s position towards the
current position. This will ensure
that all colliders between both
positions will be caught. You could
also use Physics.SphereCast etc. There
sould be a sample script implementing
this method somewhere on the net,
possibly on the Unity user wiki.