Each physics frame, cast a ray from where the projectile is to where it will be, with intersect_ray(), and count a hit on the first thing in between. A projectile that only moves and waits for a collision is checked where it lands each frame, so at high speed it jumps over thin targets. In our Godot 4.7 test an Area3D bullet at 150 m/s, 2.5 m per frame, hit a target 0.6 m thick, as thick as a character, only 7 times out of 20. The script hit 20 out of 20.
The code
Make this the root of the projectile scene and put the mesh, trail or particles under it. It flies along its -Z, Godot's forward, so spawn it with the gun's or hand's rotation. Connect hit to deal damage and spawn the impact effect at point: the projectile stops on the surface it hit.
extends Node3D
## A fast projectile that cannot skip through thin enemies or walls.
## Every physics frame it checks the whole line it is about to cover, not only the point where it lands.
signal hit(target: Node3D, point: Vector3)
@export var speed := 80.0 # metres a second
@export var max_range := 200.0
@export_flags_3d_physics var mask := 1 # the physics layers it can hit
@export var hit_areas := false # turn on if enemies use Area3D hurtboxes: rays skip areas unless asked
var _travelled := 0.0
func _physics_process(delta: float) -> void:
var from := global_position
var to := from - global_basis.z * speed * delta # flies along its -Z, Godot's forward
var q := PhysicsRayQueryParameters3D.create(from, to, mask)
q.collide_with_areas = hit_areas
var r := get_world_3d().direct_space_state.intersect_ray(q)
if r:
global_position = r.position # stop on the surface it hit, for the impact effect
hit.emit(r.collider, r.position)
queue_free()
return
global_position = to
_travelled += speed * delta
if _travelled >= max_range:
queue_free()
What we measured
20 projectiles at once, each starting a little further back so they reach the target at every point in a frame. The target is 0.6 m thick, the physics runs at 60 frames a second. The Area3D version is a sphere 0.2 m across that moves position every physics frame and counts body_entered. Two runs gave the same results.
- 30 m/s, 0.5 m per frame: the Area3D hit 20 of 20, the script 20 of 20.
- 80 m/s, 1.33 m per frame: the Area3D 13 of 20, the script 20 of 20.
- 150 m/s, 2.5 m per frame: the Area3D 7 of 20, the script 20 of 20.
- Where it hit: the Area3D noticed the target with its centre up to 0.70 m past the front face, so an impact effect there sits inside the enemy. The script's hit point was on the front face every time, 0.000 m off.
- An Area3D hurtbox instead of a body, at 80 m/s: the script with
hit_areasoff hit 0 of 20, with it on 20 of 20.
Why fast projectiles fly through
Physics checks shapes where they are at the end of each physics frame, not along the way. When a projectile moves further in one frame than the target is thick plus its own size, some frames end before the target and the next one already past it, and nothing ever overlaps. At 60 frames a second that starts at about 48 m/s for a 0.6 m target and a 0.2 m bullet, and the faster it goes, the more shots slip through. A ray covers every point between the two positions, so the speed no longer matters.
What to change
speed: metres a second. Any speed works the same.mask: the physics layers it can hit. Leave the shooter's own layer out so it cannot hit itself.hit_areas: on when enemies use Area3D hurtboxes. Rays skip areas unless this is on.- The ray is a thin line through the centre of the projectile, which suits bullets and arrows.
Aiming the shot: make the shot hit the crosshair. Placing the impact: spawn the hit effect at the impact point.
Effects for the shots: Battle VFX Bundle for Godot 4 has 169 effects from 5 packs: FPS gun effects, spell projectiles with cast, trail and hit, block and parry effects, AoE telegraphs and status effects.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: Battle VFX Bundle for Godot 4 has 169 ready-made combat effects from 5 packs: gun effects, spell projectiles with cast, trail and hit, block and parry, AoE telegraphs and status effects.
More how-tos for Battle VFX Bundle for Godot 4: Knockback that the walk code does not cancel · An attack that hits even when a frame is slow
More how-tos: Projectiles and aiming
- A ball that hits the net however hard it is kicked
- 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
- 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