Godot Version
4.4.1
Question
I’m pretty new to godot and have started to create a little twin stick shooter prototype. Everything has been smooth until I got to bullets vs world collision detection. I am on godot 4.4.1.
I am using an Area3D with monitoring/monitorable enabled and my stage bounds are just CSGBox that if I am not mistaken generate StaticBody3D collisions.
My problem is that sometimes when firing, some collisions are detected and others don’t depending of the distance of the fire point against the CSGBox. My CSGBox is pretty wide and the bullets stay inside the CSGBox while moving several frames.
Key points:
1 - Bullet is using Area3D
2 - Walls are using a CSGBox
3 - I detect collisions manually using get_overlapping_bodies on the bullet. I have tried to await a frame as documentation states but I get same result. All movement and collision detection is made inside _physics_process. Code below of my weapon class that is the one that generates the bullets and handle collsiion:
func _physics_process(delta: float) -> void:
var i=0;
while i<used_bullets.size():
var bullet = used_bullets[i];
var bodies = bullet.get_overlapping_bodies();
if bodies.size() > 0:
get_tree().root.remove_child(bullet)
pool_mgr.getPool(pool_id).recycle(bullet)
used_bullets[i] = used_bullets[used_bullets.size()-1]
used_bullets.pop_back()
print("Collided!")
else:
i+=1;
bullet.position +=-bullet.transform.basis.z*delta*40
Here is a screenshot of my test level:
Why can this be happening? I can upload a little video if needed to clarify anything.
Thanks in advance!