How to make footsteps sound different depending on the terrain texture?
I would like to do this, but I havent been exposed to the elements in C# that would let me do this. Could someone help? I need a good explanation.
I would also like to know this.
The best way I currently know of is to simply have a global (level-wide) footstep sound bank corresponding to the type of terrain you're most likely to walk on (for example grass), and then manually add trigger boxes which temporarily override the sound over other surfaces (like gravel path or rocks) over the areas that need changing.
But that results in clear cut to another sound type and sometimes you don't want that, and also it's a pain in the butt to set up if you have curvy roads or a lot of different surfaces of the terrain.
Either raycast downwards and check for some value, for example the material that is used for the object that was hit, or (for tile-based meshes) do it by continuously checking the player's x,y position against the tile array and finding out the texture/terrain type/whatever that way. Then you need to play the right sound depending on the texture/terrain type, for example by keeping a dictionary where string is the material name.
As I have written, you can get the material of the object that was hit by the raycast by accessing it's $$anonymous$$eshRenderer component. If the objects has multiple materials, you might have to use GetTriangleIndex or similar to get the right one.
http://answers.unity3d.com/questions/166111/get-terrain-texture.html
this explains how to deter$$anonymous$$e the different materials on a terrain, I'm not exactly sure how its done but it seems you can check the weight of the splatmap.
Your answer
Follow this Question
Related Questions
Raycasthit explanation wanted. 2 Answers
Explain location of Database Files with SQLite 0 Answers
Shader explain 0 Answers
Shader metallic effect 0 Answers
Picture frame around minimap 0 Answers