Physics Tunneling
Scenario: Fast-moving bullets pass through thin walls. Sometimes they hit, sometimes they go straight through. The collision code is correct.
Setup
Bullet:CharacterBody3Dwith aSphereShape3D(radius 0.05) moving at 80 units/secondWall_East:StaticBody3Dwith aBoxShape3D(size [0.3, 3.0, 5.0]) — 30cm thick- The bullet moves via
move_and_slide()in_physics_process
At 80 units/second and 60Hz physics, the bullet moves 1.33 meters per tick. The wall is 0.3 meters thick. The bullet travels 4.4x the wall's thickness in a single physics step.
Godot's move_and_slide does not use continuous collision detection by default. If the bullet starts outside the wall and ends outside the wall in one tick, the engine reports no collision — even if the wall was in between.
Step 1: Reproduce with recording
Click Record in the Spectator dock, fire several bullets at the wall at different angles and distances, then click Stop when you have captured a few tunneling events.
Step 2: Query the recording
Step 3: Find the tunneling frame
Step 4: Confirm the diagnosis
Step 5: Apply the fix (Option 3 — manual raycast)
The bullet script gets a raycast check:
gdscript
# In Bullet._physics_process()
var prev_position = global_position
move_and_slide()
# Check if we tunneled through anything
var space = get_world_3d().direct_space_state
var query = PhysicsRayQueryParameters3D.create(prev_position, global_position)
query.collision_mask = collision_mask
var result = space.intersect_ray(query)
if result:
# Handle the hit at result.position
_on_hit(result.collider, result.position, result.normal)
queue_free()Step 6: Verify the fix
Key takeaways
- Tunneling is a per-tick displacement problem, not a code bug. The physics code is correct; the geometry is too thin for the speed.
- The clip recording made this diagnosable. Without frame-by-frame position data, you would only know "sometimes it goes through" — not the exact displacement that causes it.
velocity_aboveconditions are powerful for physics bugs. They filter thousands of frames down to the ones where speed is high enough to cause tunneling.- Three valid fixes exist; the right choice depends on your game type. Manual raycasts are the most flexible for custom bullet behavior.