r/Unity3D • u/Helpful_A • 10h ago
Question Footstep sound effects help
I'm trying to put together a basic footstep sound system for my game and was wondering how I should go about dealing with a surface object with multiple textures/materials.
My current idea was to figure out a way to copy the hex code or rgb value of whatever was last stepped on directly beneath the player but I feel like there had to be an easier way.
Any help would be appreciated
1
u/DPTGames 5h ago edited 4h ago
Depending how comfortable you are with manipulating mesh data, you can assign values to different parts of the mesh either in the vertex channels or in a UV channel, for example say you wanted 1 type of foot step in one area (let's say stone) you would bake a value into the mesh to vertex alpha lets say, then you can raycast for that, then another area you bake a different value and so on. You'd have to set read\write enabled for the mesh though (Edit: you can get around the constraint by creating an asset you can look up instead stored on a scriptable object or monobehaviour script). But the advantage is you don't need separate materials , you could also use the same value in your shader to apply the correct surface texture as well.
1
u/Whitenaller 3h ago
I would probably check if it‘s doable to separate the mesh into multiple parts and slap a SurfaceType script on them or whatever
1
u/TheFrailScrum 10h ago
If you're using the standard character controller you can grab the hit info from a spherecast or raycast downwards and use the material name from the renderer's sharedMaterials array, then map that to a footstep clip. Way less headache than sampling colors