playMaker

Author Topic: Get Material Index of Faces Entered by Foot Trigger (to choose sounds)  (Read 2309 times)

westingtyler

  • Sr. Member
  • ****
  • Posts: 277
    • My Video Game Projects Web Site
My current method for choosing footstep sounds to play, is getting the tag of the object your foot's trigger entered. But this means I need tags for Dirt, Sand, Concrete, etc., etc. which is really cumbersome. It also won't work correctly if a place the player steps on has multiple textures on it, like a path through the woods that has dirt, stone, and mud on the same game object but in different spots.

Another method is to have a billion empty game objects named different things, placed throughout the map, and check distance among all of them with each step to determine which is closest to the player. But that seems costly.

Is there some way to check the polygon face directly beneath the player's foot, that it collides with, and get the material index of THAT face? If so, this would save a lot of hassles getting the correct footsteps to play automatically based on which textures I use in the game.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Get Material Index of Faces Entered by Foot Trigger (to choose sounds)
« Reply #1 on: February 06, 2019, 12:53:18 AM »
Hi.
Have you tried using raycast?
As a raycast is a straight line.

maybe you can use get material and use that to check which kind of floor you are walking on.

for example with 2 arrays, one with the materials and 1 with the sounds.

then match the sounds/materials by index and you can use 'Array Contains' to get the index

westingtyler

  • Sr. Member
  • ****
  • Posts: 277
    • My Video Game Projects Web Site
Re: Get Material Index of Faces Entered by Foot Trigger (to choose sounds)
« Reply #2 on: February 07, 2019, 10:56:47 AM »
If I ray cast from the character down to the ground, that will return the game object hit, right? Not the material of the face of the game object hit?

So if the character walks onto some gravel-textured faces (landscape 1 game object, material index 1), won't this ray cast method just return the same result (the same game object) as it would if the player walked two steps to the left, onto the grass (landscape 1 game object, material index 0).

In the Raycast action, I don't see a box under the RESULT section to save the material at the hit point. Am I missing something?

I can get the "hit point" and the "hit normal" using ray cast, but how do I convert that into the name of the material of that face on the mesh?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Get Material Index of Faces Entered by Foot Trigger (to choose sounds)
« Reply #3 on: February 07, 2019, 12:03:04 PM »
Hi,
i did a quick search on unity and found this post :

https://answers.unity.com/questions/484583/checking-material-on-raycast.html

with a link to this post :

https://forum.unity.com/threads/get-material-from-raycast.53123/


Then i search for "triangleIndex" in the Ecosystem and found 3 actions which can get material.

Maybe these can help :)