Cast a short ray down from the feet, read a name from what it hits, and pick the puff by that name. On a normal floor body, store the name with set_meta. On a GridMap the ray hits the GridMap node itself, so look up the cell under the hit point and use the item name from the MeshLibrary. Drop a puff every 0.6 meters walked on the ground, not on a timer.

The code
Add a Node3D as a child of your character, at the feet, and give it this script. On each floor body, add the name: floor.set_meta("surface", "sand"), or in the Inspector under Metadata. Connect stepped if you also want a footstep sound per surface.
extends Node3D
## Footstep puffs that match the ground: sand, snow, grass or any name you give it.
## Add it as a child of the character, at the feet. It drops one puff every `stride` meters
## while there is ground under it. Name the ground with set_meta("surface", "snow") on a
## floor body, or with the item names in your GridMap's MeshLibrary.
signal stepped(surface)
@export var stride := 0.6 # meters between two steps
@export var colors := {
"sand": Color(0.85, 0.72, 0.45),
"snow": Color(0.95, 0.97, 1.0),
"grass": Color(0.45, 0.7, 0.3),
"default": Color(0.6, 0.55, 0.5),
}
var _ray := RayCast3D.new()
var _last := Vector3.ZERO
var _walked := 0.0
func _ready() -> void:
_ray.position = Vector3(0, 0.1, 0)
_ray.target_position = Vector3(0, -0.3, 0) # 20 cm below the feet
add_child(_ray)
_last = global_position
func _physics_process(_delta: float) -> void:
var p := global_position
var flat := Vector2(p.x - _last.x, p.z - _last.z).length()
_last = p
if not _ray.is_colliding():
_walked = 0.0 # in the air: start counting again after landing
return
_walked += flat
if _walked >= stride:
_walked -= stride
var s := surface()
_puff(colors.get(s, colors["default"]))
stepped.emit(s)
func surface() -> String:
if not _ray.is_colliding():
return ""
var col := _ray.get_collider()
if col == null: # the floor was just freed
return "default"
if col is GridMap: # one collider for the whole map: ask which cell is under the feet
var gm: GridMap = col
var inside := _ray.get_collision_point() - _ray.get_collision_normal() * 0.05
var item := gm.get_cell_item(gm.local_to_map(gm.to_local(inside)))
if item != GridMap.INVALID_CELL_ITEM:
return gm.mesh_library.get_item_name(item)
elif col.has_meta("surface"):
return str(col.get_meta("surface"))
return "default"
func _puff(c: Color) -> void:
var fx := GPUParticles3D.new()
fx.one_shot = true
fx.amount = 12
fx.lifetime = 0.6
fx.explosiveness = 0.9
fx.local_coords = false
var pm := ParticleProcessMaterial.new()
pm.direction = Vector3.UP
pm.spread = 70.0
pm.initial_velocity_min = 0.6
pm.initial_velocity_max = 1.4
pm.gravity = Vector3(0, -3, 0)
pm.color = c
fx.process_material = pm
var q := QuadMesh.new()
q.size = Vector2(0.12, 0.12)
var m := StandardMaterial3D.new()
m.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
m.vertex_color_use_as_albedo = true
m.billboard_mode = BaseMaterial3D.BILLBOARD_PARTICLES
q.material = m
fx.draw_pass_1 = q
get_tree().current_scene.add_child(fx) # in the level, so it stays where the foot was
fx.global_position = global_position
fx.finished.connect(fx.queue_free)
fx.restart() # not emitting = true: restart() makes finished fire, so the puff frees itself
We moved it 10 meters at 5 meters per second, across a sand floor and then a snow floor: 8 sand steps and 8 snow steps. The last sand step was 0.17 meters before the border and the first snow step 0.42 meters after it, so the change happens on the next step.
Steps by distance, not by time
Standing still for one second gave 0 steps. Moving 5 meters while 2 meters above the floor gave 0 steps too, because the ray did not reach the ground. After landing, the first step came 0.75 meters later, a little more than one stride. A timer would keep stepping in both cases.
GridMap floors
If your level is a GridMap, get_collider() returns the GridMap node, the same one for every cell, so a metadata name cannot tell sand from snow. That is why surface() moves the hit point 5 centimeters into the floor, finds the cell there and reads the item name. On a GridMap of sand and snow cells, every step got sand or snow, and none fell back to default.
The puffs clean up after themselves
One second after the last step, 0 puffs were left in the scene. That needs restart(): the same puff started with emitting = true was still there 1.5 seconds later, because finished never fired. More on this: remove a one-shot particle effect when it ends.
What to change
stride: about the length of one step of your character at running speed.colors: add a name for every floor you have. Unknown names use default.- The ray reaches 20 centimeters below the feet. Make it longer if your character floats a bit above the floor.
_puff(): replace it with your own effect scenes per surface. Keep therestart().
Dust behind a running character instead of per step: running dust particles.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: Movement VFX for Godot 4 has ready footstep effects for dust, sand, snow and water, and its README says to spawn a new one per step so the earlier dust keeps playing.
More how-tos: Play, stop and remove effects
- Remove a one-shot particle effect when it ends
- Fade out and stop looping particles
- Spawn a hit effect facing the surface
- Hit sparks from a pool of emitters
- Changing one particle effect's color changes all of them
- Particles that play the same way every time
- Freeze particles in mid-air
- Running dust and landing puffs
- Particles left behind by a moving object
- 2D particles follow the player or stay behind
- A level up effect that plays while paused
- Hide particle effects far from the camera
- Death particles disappear when the enemy is freed
- Remove all particles at once