A RigidBody3D moves in steps, one per physics tick, so a fast ball can land past a thin wall, or so far into it that it is pushed out the other side. In our Godot 4.7 test a football, 22 cm across, shot at a 5 cm thick wall went through 3 times in 10 at 10 m/s, 6 times at 20 m/s and 9 times at 80 m/s, with the default settings of a new project. With continuous_cd on, it went through 0 times at every speed. Doubling the physics ticks to 120 still let 6 in 10 through at 40 m/s.
The code
Save it as fast_body.gd and call preload("res://fast_body.gd").prepare($Ball, 40.0, 0.05) once when the ball is made, with the fastest it will ever go in m/s and the thinnest wall, post or net it must not pass, in metres. It turns continuous_cd on when that speed is high enough for a wall to be missed. You can also just tick Continuous CD on the RigidBody3D in the Inspector.
extends RefCounted
## Stops fast RigidBody3D balls and bullets from passing through thin walls,
## goal posts and nets. A body moves in steps, one per physics tick. If a step
## jumps over the wall, or lands with the body's centre already past the
## middle of the wall, the body comes out on the far side.
## FastBody.prepare($Ball, 40.0, 0.05) # top speed in m/s, thinnest wall in m
## Turns on continuous collision detection when the body is fast enough for
## that to happen, with a 25% margin.
static func safe_speed(body_size: float, wall_thickness: float, ticks := Engine.physics_ticks_per_second) -> float:
return (body_size + wall_thickness) * 0.5 * ticks * 0.75 # one step = half the body + half the wall, less 25%
static func prepare(body: RigidBody3D, top_speed: float, wall_thickness: float) -> bool:
var size := _size(body)
body.continuous_cd = top_speed >= safe_speed(size, wall_thickness)
return body.continuous_cd
static func _size(body: RigidBody3D) -> float: # the smallest width of the body's first shape
for c in body.get_children():
if c is CollisionShape3D and c.shape != null:
var s: Shape3D = c.shape
if s is SphereShape3D:
return s.radius * 2.0
if s is CapsuleShape3D:
return s.radius * 2.0
if s is BoxShape3D:
var b: Vector3 = s.size
return minf(b.x, minf(b.y, b.z))
return 0.1
What we measured
A RigidBody3D sphere of radius 0.11 m and 0.43 kg with no gravity, sent straight at a 5 cm thick StaticBody3D wall 5 m away, at 60 physics ticks. Each shot was 10 balls side by side, each starting a tenth of a physics step further back, so where the steps happened to land did not decide the result. Two runs gave the same counts.
- Default settings, balls through out of 10: 5 m/s 0, 6 0, 7 0, 8 1, 10 3, 20 6, 40 8, 80 9.
continuous_cd = true: 0 out of 10 at every speed from 5 to 80 m/s.- The script, which turns it on from 6.1 m/s for this ball and wall: 0 at every speed.
- 120 physics ticks, default settings: 10 m/s 0, 12 0, 16 2, 40 6. The script's line moves to 12.2 m/s.
Why it happens
Each tick the engine moves the ball by its speed divided by the tick rate, then checks what it overlaps. At 20 m/s and 60 ticks that is 33 cm per step, more than the ball and the wall together, so some steps start in front of the wall and end behind it. Slower than that, a step can still end with the ball's centre past the middle of the wall, and pushing it out the nearest way then means out the far side, which fits the balls lost at 8 and 10 m/s. Continuous collision detection checks the whole path of the step, not just where it ends.
What to change
- Bullets that do not need to bounce can skip the body and cast a ray along each step instead, see a raycast each frame.
- Kicks that come out too weak or too strong: force or impulse. Showing where the ball will go: a trajectory line.
What the shot looks like: Sports & Ball Game VFX for Godot 4 has 32 ready-made sports effects in Stylized and Retro PSX looks, including charge shots in 3 levels, kick impacts, ball trails and a goal net ripple.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: Sports & Ball Game VFX for Godot 4 has 32 ready-made sports effects in Stylized and Retro PSX looks, including charge shots in 3 levels, kick impacts, ball trails and a goal net ripple.
More how-tos: Projectiles and aiming
- A shot that meets a moving target
- An Area3D that does not see a bullet or another area
- A fire rate that holds at any frame rate
- Point swords, projectiles and models that face +Z at the target
- FPS shots that land on the crosshair
- A spell that keeps flying straight after it leaves the hand
- Turn towards a target the short way round
- A laser beam that stops where it hits, the moment you aim
- Fast projectiles that never fly through enemies
- A trajectory line that matches where the ball lands
- Aim a spell at the mouse on a 3D floor
- A homing missile that turns, but not instantly
- Particles fall sideways when you rotate the emitter
- Particles that fly into the player
- Gaps in the trail of a fast emitter
- Make a tower shoot the enemy closest to your base
- Hit the target with an arcing shot at any angle and height
- Kick a RigidBody3D ball with the same strength at any tick rate
- Reload without losing or making up rounds
- Fan out any number of projectiles evenly around the aim direction
- Recoil that settles back to where the player aims