← Pixel Dreamer Studio

Emit particles along a Path3D

Turn the curve into emission points, in the emitter's own space.

A ParticleProcessMaterial has no path shape, but it can emit from a list of points. Sample the Path3D's curve with sample_baked(), write the positions into an image, and give it to emission_point_texture with EMISSION_SHAPE_POINTS. The points are in the emitter's own space, so convert each one with global_transform.affine_inverse(). In our Godot 4.7 test, 98% of the lit points were within 12 pixels of the curve. Without the conversion, with the emitter 1 m above the path: 0%.

Light blue sparks forming a wave-shaped line on a dark background
The script in Godot 4.7 with the Compatibility renderer, enlarged 2 times. The Path3D is a wave-shaped curve, and the emitter sits 1 m above it.

The code

Attach this to a GPUParticles3D and set path to your Path3D. points is how many places along the curve the particles can start from.

extends GPUParticles3D
## Sparks that come out all along a Path3D's curve, like a magic line or an electric fence.
## Set path to a Path3D. Its curve becomes a list of emission points once, in _ready().

@export var path: Path3D
@export var points := 200


func _ready() -> void:
	var curve := path.curve
	var length := curve.get_baked_length()
	var img := Image.create(points, 1, false, Image.FORMAT_RGBF)
	for i in points:
		var world := path.global_transform * curve.sample_baked(length * i / (points - 1))
		var p := global_transform.affine_inverse() * world  # emission points are in this node's space
		img.set_pixel(i, 0, Color(p.x, p.y, p.z))
	amount = 300
	lifetime = 0.8
	var m := ParticleProcessMaterial.new()
	m.emission_shape = ParticleProcessMaterial.EMISSION_SHAPE_POINTS
	m.emission_point_texture = ImageTexture.create_from_image(img)
	m.emission_point_count = points
	m.direction = Vector3.UP
	m.spread = 30.0
	m.initial_velocity_min = 0.1
	m.initial_velocity_max = 0.3
	m.gravity = Vector3.ZERO
	process_material = m
	var mat := StandardMaterial3D.new()
	mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
	mat.billboard_mode = BaseMaterial3D.BILLBOARD_PARTICLES
	mat.albedo_color = Color(0.5, 0.9, 1.0)
	var q := QuadMesh.new()
	q.size = Vector2(0.06, 0.06)
	q.material = mat
	draw_pass_1 = q

What we measured

A wave-shaped curve 6 m wide, with the emitter placed 1 m above the Path3D. One second in, we counted the lit points and how many of them were within 12 pixels of the curve on screen. Two runs of each.

If the path or the emitter moves

The points are worked out once, in _ready(). If you move the Path3D or the emitter later, or edit the curve, run that loop again.

What to change

Particles from the surface of a mesh instead: particles from a mesh surface. A line that jumps between enemies: chain lightning.

Tested in Godot 4.7 with the Compatibility renderer.

More how-tos: Auras, rings, beams and weather