← Pixel Dreamer Studio

GPUParticles2D collision: fall through or vanish

2D particles hit light occluders, not physics bodies.

Set collision_mode in the ParticleProcessMaterial to Rigid, which is off by default, and give the floor a LightOccluder2D with sdf_collision on. A StaticBody2D in the same place did nothing in our test: 2D particles use occluders, not physics shapes. With collision on and no occluder that has SDF Collision on, no particle showed at all in our test. It works in the Compatibility renderer.

Two fountains of small orange sparks above a grey floor line. The left sparks fall through the line to the bottom of the screen. The right sparks stay above it
The script below in Godot 4.7 with the Compatibility renderer. Left: Collision Mode off, the default. Right: the script as written. The grey line only shows where the occluder is.

The code

Attach this to a Node2D for sparks that jump up, fall and bounce on a floor 260 pixels below the node. It makes the floor itself, a LightOccluder2D, and a small square texture for the sparks. The lines marked fix 1 and fix 2 are the two settings.

extends Node2D
## 2D sparks that fall and bounce on a floor. GPUParticles2D do not hit physics bodies:
## they collide with LightOccluder2D shapes that have SDF Collision on.

var sparks := GPUParticles2D.new()
var floor := LightOccluder2D.new()


func _ready() -> void:
	var poly := OccluderPolygon2D.new()  # the floor: a box 600 px wide, its top edge 260 px below this node
	poly.polygon = PackedVector2Array([Vector2(-300, 260), Vector2(300, 260), Vector2(300, 300), Vector2(-300, 300)])
	floor.occluder = poly
	floor.sdf_collision = true  # fix 1: the occluder takes part in particle collision
	add_child(floor)
	sparks.amount = 60
	sparks.lifetime = 2.0
	sparks.texture = make_dot()
	var m := ParticleProcessMaterial.new()
	m.direction = Vector3(0, -1, 0)
	m.spread = 40.0
	m.initial_velocity_min = 150.0
	m.initial_velocity_max = 250.0
	m.gravity = Vector3(0, 500, 0)
	m.collision_mode = ParticleProcessMaterial.COLLISION_RIGID  # fix 2: off by default
	m.collision_bounce = 0.4
	m.collision_friction = 0.2
	sparks.process_material = m
	sparks.collision_base_size = 6.0
	add_child(sparks)


func make_dot() -> Texture2D:
	var img := Image.create(6, 6, false, Image.FORMAT_RGBA8)
	img.fill(Color(1.0, 0.75, 0.3))
	return ImageTexture.create_from_image(img)

What we measured

The emitter was 260 pixels above the top of the floor. After 1.5 seconds we counted lit points on a grid of every second pixel, added up over 10 frames, above the floor, in the 40 pixels just above it, and below it. Three runs gave close numbers.

Floors you already have

If your floor is a StaticBody2D or tiles with physics shapes, add a LightOccluder2D with the same shape where particles should land. Our test scene had no lights: SDF Collision worked on its own.

What to change

The 3D version, with a collision box: particles fall through the floor. 2D particles that do not show for other reasons: GPUParticles2D not showing.

Tested in Godot 4.7 with the Compatibility renderer.

More how-tos: When particles do not show up