Should i use Area2D for bullet?

Godot Version

4.5.stable

Question

Since the annoying body_entered signal delay, if a enemy is not big enough, players will defnitely see the bullet disappear behind a enemy rather than disappear when hit the enemy. I don’t have any way to detect collision in current frame.
image
Here is a little test: The bullet moving from left to right, it will stops on body_enter signal. You can see the small square collisionshape stops behind the enemy, some of them even out of the collision area. I give it a speed 1000 per second which is not very high for a bullet.

So why CharacterBody2D can handle the collision well but Area2D can not? I give a Character2D the same speed and it never go through a StaticBody2D.

Most tutorials say that you should use Area2D for the bullet but no one ever mentioned this problem. Did i used it in a wrong way?

Character bodies using move_and_slide may be moving in smaller multiple steps per frame. Area2D cannot sample multiple positions in a single frame sadly, You could extend the Area2D to be longer, especially behind it’s visual since it’s moving fast this should feel perfectly fine. Another option is to use a raycast instead of an Area2D.

5 Likes

Thanks! I put a raycast at top of the bullets. It works fine by force_raycast_update() every frame.

But i still think this is a really hacky solution since this is not raycast designed for and may cause other issue.

I don’t know why godot can’t handle these basic demands.

Continuous collision detection is not a basic demand. It’s a computationally expensive operation. If you have small number of bullets, use character bodies otherwise use raycasts or shapecasts in addition to areas. If you experience bottlenecks with them, switch them on only when bullet is near enough to a possible target. You’ll potentially need to implement some kind of space partitioning scheme for that. But do so only if bruteforce causes significant bottlenecks detectable in the profiler.

2 Likes

Got it. Thank you!