Godot Version
4.3
Question
Hi, I’m trying to revamp the sound system in my game, and part of that is switching the sounds played you step to be based on the surface you are on rather than the previous system (a super scuffed gamejam implementation that determined the sound based-on the level id). I know I’d need some sort of dictionary or long match statement for each material in the game.
So I attempted to do this in the code snippet here
func find_step_sound():
var floor = material_checker.get_collider()
var floor_material_node = floor.get_node_or_null("MeshInstance3D")
var floor_material = null
if floor_material_node != null:
floor_material = floor_material_node.get_mesh().get_material()
print(floor_material)
match floor_material:
"res://Assets/3d/materials/world_map.tres":
step_sound = snow_footsteps.pick_random()
"res://Assets/3d/materials/stairs.tres":
step_sound = stair_footsteps.pick_random()
The issue is, no matter what surface I’m on floor_material
returns null. I’ve tried reading the documentation for the RayCast3D node and the MeshInstance3D, and I’m unsure what I’m doing wrong. I’ve found some Godot 3-era Reddit posts discussing a similar system, but trying to transfer it over to Godot 4-era naming conventions hasn’t helped either.
Any help would be much appreciated!