How to darken mesh/model (e.g. based on health status)

Question about simulating game object visible decay/damage.
How to darken a mesh/model based on health status (number between 0.0 and 1.0)?
Say I have a crate mesh model imported. The crate takes 5 shots before break. At each shot hit the crate becomes a bit more darker. This shows the player that the crate is getting damaged.
I am looking for an effect that is reversible, e.g. when crate heals/repairs than the darkened effect wears off / I can undo the effect without messing up the mesh itself.
Here’s a screenshot of a game I saw this effect in:
image
The bins in the picture start bright colored, but now some as darkened or completely black/dark grey as they have been destroyed by bullets.
Q

Babylon.js Playground I am not sure if this is the smartest way. But maybe it helps you. If you are willing to use PBRMaterial and hdr reflection, you can control value of environmenIntensity of the material which will make mesh completely dark when 0;

1 Like

You could use an overlay color:

https://playground.babylonjs.com/#U8MEB0#71

2 Likes

Both solutions seem to work. I chose the solution of @Gijs because that one takes the least resources and is very straightforward to use. Didn’t know about the overlay option, couldn’t find it in the docs when searching for material options, so thanks I learned something new today :slight_smile:

The result:


Good Health (green hitpoint bar, no mesh overlayColor, bright & shiny model)


Average Health (yellow hitpoint bar, mesh overlayColor)


Bad Health (red hitpoint bar, mesh overlayColor)


Critical Health or Destroyed (even darker mesh overlayColor)

How about that for some visual queues on health status :man_health_worker:

2 Likes