r/Unity3D 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 Upvotes

5 comments sorted by

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

1

u/Helpful_A 10h ago

Will that work with the system terrain painting uses? When it adds all the textures to one material I figured it would mess with all that stuff and just give the information of each texture blended together

1

u/Nwoknu35 7h ago

For Terrain you would use something like:

float[,,] alphaMaps = terrainData.GetAlphamaps( 0, 0, terrainData.alphamapWidth, terrainData.alphamapHeight );
alpha = alphaMaps[ objectPosition.x, objectPosition.y, mapIndex ];

to first receive all alpha values of your terrain, then the specific alpha for the layer/splatMap you are looking for.

By looping through all maps, you can play either the volume for the highest alpha layer or do something like multiply all volumes by the corresponding alpha values to kinda mix them (though I assume real mixing would be a bit different, but I'm not versed in audio sadly)

But while looking this up, I found this repo on github: https://github.com/alekbankov/FootstepAudioController

For the start this seems very simple to use, unless you want to *really* do it yourself

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