Page 1 of 1

Face's material detection based on raycasting...

Posted: Tue Nov 15, 2011 12:06 am
by Alonguy
OK, so I was wondering if anyone has a good method for this. I have a player, 3rd-person view. Now, when they walk, I want different sounds to play for footsteps based on the surface they're walking on. I once tried a method where I made every different kind of surface into a separate mesh and detected what node the player is on through raycasting. But this way is pretty hard to work with. Basically, I want to be able to cast a ray below the player, and determine what material the face below them is. Does anyone know any good way to do this?
Any help is appreciated.

Re: Face's material detection based on raycasting...

Posted: Tue Nov 15, 2011 2:56 am
by mongoose7
Looks straightforward to me. The terrain is generated from a heightfield. The player is at the point (x, y, z). (x, y) is the base point on the ground plane. Choose your sounds based on (x, y).

Re: Face's material detection based on raycasting...

Posted: Tue Nov 15, 2011 3:25 am
by Adler1337
Good question. I have yet to find a good solution to this problem. I'm looking forward to hearing some ideas.
@mongoose7: That solution would only work for basic games/tech demos. What if you are not using a heightfield at all? Or multi-story buildings?

Re: Face's material detection based on raycasting...

Posted: Tue Nov 15, 2011 4:20 am
by Alonguy
Hmm... I suppose I COULD go back to the old way of setting up nodes for different materials. And since I'm now using XEffects for lighting, I don't think the normals should matter, so they don't NEED to be connected... and I'm using Newton for physics and I have separate collision maps for my levels... And I'm actually doing an action-RPG type deal. Determining materials would also make it easy to do things like make ladder/vine materials climbable. (once I figure how to do a climbing system).
But if it requires a ton of Irrlicht hackery, I don't think I wanna do it. XD
But if anyone does know a good method, I would really, really appreciate it.

Re: Face's material detection based on raycasting...

Posted: Tue Nov 15, 2011 9:48 am
by CuteAlien
I worked with separate invisible polygons for that in the past (trigger areas). I don't think there's an easy way to get to the material.

Re: Face's material detection based on raycasting...

Posted: Tue Nov 15, 2011 1:50 pm
by hendu
Q3 does that with the materials; can't remember right now how exactly, but you have the code.

edit: It uses a short raycast, and then tests the material's parameters.

Re: Face's material detection based on raycasting...

Posted: Tue Nov 15, 2011 10:15 pm
by Klunk
Don't know anything about Newton, but I would have thought encoding this kind of data in the collision, and getting the physics to access it. In my own simpleton homebrew physics I encode a matid for every face in collision mesh. this matid maps to the materials on the visible geometry which has info on the dynamic surface properties, cr, friction etc. Its then very simple process for the physics to access the face , and therefore the material, where a collision occurs.

Re: Face's material detection based on raycasting...

Posted: Wed Nov 16, 2011 1:48 am
by RdR
An other idea might be to create some sort of material color map.
An external image with defines the material / sound 'type' by different colors in a image.
Each color represents an material or sound.

Convert the world coordinates to the image x,y coordinates and get the color to check which sound to play

Re: Face's material detection based on raycasting...

Posted: Wed Nov 16, 2011 8:31 am
by Virion
in Unreal Engine for example it uses the physical material http://wiki.beyondunreal.com/UE3:PhysicalMaterial_(UDK) basically detecting the collided object and get the sound from its physical material based on the action (fracture, impact, sliding)