Discriminating material types on collision for choosing appropriate bullet hit effects and footstep sounds #97

Open
opened 2021-10-12 01:37:41 +02:00 by unfa · 1 comment

We need to define a resource type extending Material to add a property carrying information about the type of the surface (glass, wood, metal, flesh, water etc.).

This will allow bullet holes, impact VFX, hit sounds, footstep sounds to match the material type.

https://docs.godotengine.org/en/stable/getting_started/step_by_step/resources.html

https://www.youtube.com/watch?v=sFz0hi_fK5g

We need to define a resource type extending Material to add a property carrying information about the type of the surface (glass, wood, metal, flesh, water etc.). This will allow bullet holes, impact VFX, hit sounds, footstep sounds to match the material type. https://docs.godotengine.org/en/stable/getting_started/step_by_step/resources.html https://www.youtube.com/watch?v=sFz0hi_fK5g
Poster
Owner

I've done this. But it won't work as I expected.

The problem is:

Collision meshes and rendered meshes are completely separate, and there is no way to get material information from that.

In the curent state of Godot the only way to deal with this is to split the level geometry into multiple Static Bodies based on used material types. Then the nodes could contain properties to communicate what kind of material the collision has occured with.

This would either require a lot of manual work or a smart import script.

I think for now we should ignore this issue and wait for possibly a better solution to emerge in Godot.

Related discussion on Godot Contributors chat:
https://chat.godotengine.org/channel/physics?msg=8Sq25knyDdoKRLWzg

Archive copy in case the source goes down:

unfa
1:08 AM
Is it possible to probe what material a ray or body has collided with on a mesh?
I can check what object was hit, but then - can I check what material the face that the collision was with actually uses?

My use case:
I want guns in my game to leave bullet holes dependant of the material the bullet has hit (quite a typical thing to do).

Calinou
1:08 AM
this should be feasible with PhysicsMaterial. Since each PhysicsBody can have only one PhysicsMaterial applied to it, you will need a different collider per material type
PhysicsMaterial is where you normally define bouncing and friction, but you can set a resource name such as grass or sand and act based on this

unfa
unfa
1:09 AM
Oh shoot. I could just as well split my level geometry by material type and use separate meshes.
So far I've defined a custom resource extending StandardMaterial3D to add "material type" property which bullets can check to spawn appropriate damage effects.
Is that a wrong approach though?

Calinou
1:10 AM
yeah, colliders can't read the rendering material they collided with
because there is no association between that material and the PhysicsBody it collided with

unfa
unfa
1:11 AM
Ah, right. The collision is totally independent.
Oh no, this is going to be a nightmare to implement.
I mean - the only way to do this is to set a property per collider object, then this property can be used to differentiate between material types.

Calinou
1:13 AM
yes, hence the need to have several StaticBodies for the level collision

unfa
unfa
1:13 AM
but that means it's not possible to say - generate a static collision sibling on a single level geometry mesh and have this work.

Calinou
1:13 AM
you could defer the collision sibling generation to a custom script or editor plugin, but it'll need some work

unfa
unfa
1:15 AM
Yeah. that's not going to be easy. I'd need to sort faces by surface and generate multiple collision siblings grouping them by surface and then assigning appropriate PhysicsMaterials I guess.
Ok, so the only way is to have separate static bodies for each material type.

fire
2:17 AM
unfa slicer?
https://github.com/cj-dimaggio/godot-slicer

github.com
GitHub - cj-dimaggio/godot-slicer: A port of Ezy-Slicer for the Godot game engine
A port of Ezy-Slicer for the Godot game engine. Contribute to cj-dimaggio/godot-slicer development by creating an account on GitHub.
not the same but similiar
oh
we want physics materials
like this material is wood
and calculate penetration
and splitting

Calinou
2:35 AM
yeah, slicing is unrelated

Lyuma
2:44 AM
Does Godot support getting the mesh UV? If so, could you use UDIMs (integer offsets on the UV) to determine a sort of material id?
never mind, it's just an array of vertices (faces)

unfa
unfa
12:32 PM
Actually all I want is to be able to spawn appropriate VFX/sound/decals and footsteps when a player walks on a surface.

fire
2:19 AM
like this material is wood
No fancy glass braking for now, but feature from FEAR is forever burned into my memory 😃

unfa
unfa
2:02 PM
I wonder if it'd make sense to have an option in mesh import to divide the collision by materials. I expect many a game will need something like this.

PouleyKetchoupp
Moderator
5:41 PM
unfa What I would rather do to properly support this case is:

  1. Expose hit triangle index in space queries and collision results, so you can have your own map with custom information.
  2. Allow optional per triangle materials in concave shape so you can have different friction/bounce parameters.
    So you can keep single collision shapes which is better for performance.

unfa
unfa
1:48 AM
That sounds nice, but I guess this'd need to be implemented as a core feature, no?

Calinou
1:50 AM
indeed
3D importers will need to be modified to support this information too (not sure how)

PouleyKetchoupp
Moderator
2:25 AM
unfa Yeah, it would need to be added in core.
Per-shape and per-triangle materials are already on my todo list for 4.0 and the other one doesn't look too difficult though.
It seems like it should be even possible to backport to 3.x without breaking compatibility (at least for Godot physics, not sure about Bullet).

I've done this. But it won't work as I expected. The problem is: Collision meshes and rendered meshes are completely separate, and there is no way to get material information from that. In the curent state of Godot the only way to deal with this is to split the level geometry into multiple Static Bodies based on used material types. Then the nodes could contain properties to communicate what kind of material the collision has occured with. This would either require a lot of manual work or a smart import script. I think for now we should ignore this issue and wait for possibly a better solution to emerge in Godot. Related discussion on Godot Contributors chat: https://chat.godotengine.org/channel/physics?msg=8Sq25knyDdoKRLWzg Archive copy in case the source goes down: > unfa > 1:08 AM > Is it possible to probe what material a ray or body has collided with on a mesh? > I can check what object was hit, but then - can I check what material the face that the collision was with actually uses? > > My use case: > I want guns in my game to leave bullet holes dependant of the material the bullet has hit (quite a typical thing to do). > > > Calinou > 1:08 AM > this should be feasible with PhysicsMaterial. Since each PhysicsBody can have only one PhysicsMaterial applied to it, you will need a different collider per material type > PhysicsMaterial is where you normally define bouncing and friction, but you can set a resource name such as grass or sand and act based on this > > unfa > unfa > 1:09 AM > Oh shoot. I could just as well split my level geometry by material type and use separate meshes. > So far I've defined a custom resource extending StandardMaterial3D to add "material type" property which bullets can check to spawn appropriate damage effects. > Is that a wrong approach though? > > > Calinou > 1:10 AM > yeah, colliders can't read the rendering material they collided with > because there is no association between that material and the PhysicsBody it collided with > > unfa > unfa > 1:11 AM > Ah, right. The collision is totally independent. > Oh no, this is going to be a nightmare to implement. > I mean - the only way to do this is to set a property per collider object, then this property can be used to differentiate between material types. > > > Calinou > 1:13 AM > yes, hence the need to have several StaticBodies for the level collision > > unfa > unfa > 1:13 AM > but that means it's not possible to say - generate a static collision sibling on a single level geometry mesh and have this work. > > > Calinou > 1:13 AM > you could defer the collision sibling generation to a custom script or editor plugin, but it'll need some work > > unfa > unfa > 1:15 AM > Yeah. that's not going to be easy. I'd need to sort faces by surface and generate multiple collision siblings grouping them by surface and then assigning appropriate PhysicsMaterials I guess. > Ok, so the only way is to have separate static bodies for each material type. > > > fire > 2:17 AM > unfa slicer? > https://github.com/cj-dimaggio/godot-slicer > > github.com > GitHub - cj-dimaggio/godot-slicer: A port of Ezy-Slicer for the Godot game engine > A port of Ezy-Slicer for the Godot game engine. Contribute to cj-dimaggio/godot-slicer development by creating an account on GitHub. > not the same but similiar > oh > we want physics materials > like this material is wood > and calculate penetration > and splitting > > > Calinou > 2:35 AM > yeah, slicing is unrelated > > > Lyuma > 2:44 AM > Does Godot support getting the mesh UV? If so, could you use UDIMs (integer offsets on the UV) to determine a sort of material id? > never mind, it's just an array of vertices (faces) > > unfa > unfa > 12:32 PM > Actually all I want is to be able to spawn appropriate VFX/sound/decals and footsteps when a player walks on a surface. > > fire > 2:19 AM > like this material is wood > No fancy glass braking for now, but feature from FEAR is forever burned into my memory 😃 > > unfa > unfa > 2:02 PM > I wonder if it'd make sense to have an option in mesh import to divide the collision by materials. I expect many a game will need something like this. > > > PouleyKetchoupp > Moderator > 5:41 PM > unfa What I would rather do to properly support this case is: > 1. Expose hit triangle index in space queries and collision results, so you can have your own map with custom information. > 2. Allow optional per triangle materials in concave shape so you can have different friction/bounce parameters. > So you can keep single collision shapes which is better for performance. > > unfa > unfa > 1:48 AM > That sounds nice, but I guess this'd need to be implemented as a core feature, no? > > > Calinou > 1:50 AM > indeed > 3D importers will need to be modified to support this information too (not sure how) > > > PouleyKetchoupp > Moderator > 2:25 AM > unfa Yeah, it would need to be added in core. > Per-shape and per-triangle materials are already on my todo list for 4.0 and the other one doesn't look too difficult though. > It seems like it should be even possible to backport to 3.x without breaking compatibility (at least for Godot physics, not sure about Bullet). >
unfa changed title from Create a custom resource type for Materials to Discriminating material types on collision for choosing appropriate bullet hit effects and footstep sounds 2021-10-15 15:28:50 +02:00
gilgamesh added the
enhancement
label 2021-12-14 15:24:37 +01:00
This repo is archived. You cannot comment on issues.
No Milestone
No project
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: unfa/liblast#97
There is no content yet.