Posted August 08, 2023 by simonschreibt
NOT in game yet but first test was successful: There will be an upgrade, that bullets can pass through enemies (but apply damage) a certain amount of times (based on upgrade level).
Bullet and enemy are rigid bodies and usually a penetration like this is not possible. Either they collide or they don't, but in the latter case no damage would be applied and you'd also not even get a notification, that a collision happened.
Solution: RigidBody-Collision is disabled at the beginning and an Area2D node (godot specific) checks for overlaps with other objects. Every time I overlap with something, I create a clone of the bullet with 0.1s lifetime and enabled rigid body collision: This will "officially" hit the enemy while the original bullets continues flying until I enable its rigid body collision as well (which will happen after x times of penetrating an enemies).
Interesting side-effect (which i like): penetrated objects are NOT pushed around. This can create interesting gameplay because pushing stuff around can help to avoid collision (as you push it away from you).