Question

So I'm working on a game in Java 3D and I'm implementing health bars that hover above units.

I started by drawing a quad at a 3D point above the unit's location and applying a Billboard behavior to make it always face the camera.

But the problem I'm stuck with is that the health bars are sometimes obscured by other scenery.

So I'm considering the following options:

  1. Overriding the Z / depth buffer value for the health bar pixels to make the renderer think they're closer to the camera than anything it renders afterwards.

    I tried renderingAttributes.setDepthTestFunction(RenderingAttributes.ALWAYS). While it makes the renderer draw the health bar on top of anything it drew in the same area earlier, it doesn't help when the other scenery is drawn on top of the health bar later.

    Is there a better way for doing this in Java 3D?

  2. Projecting the 3D locations of the health bars onto a 2D plane in front of the camera. Sounds doable, but before I set off reinventing all the math required for this, maybe someone can point out an existing solution.

  3. Switching from Java 3D to something like LWJGL or jMonkeyEngine (not just for this issue, but general complaints about Java 3D being dead, etc). Although I'm not even sure whether they're more flexible for this particular problem. And from what I've read, one of the worst mistakes in game dev is switching the engine in mid-development.

Was it helpful?

Solution

Use the painter's algorithm: draw the health bars after you've drawn the rest of the scene (and with Z testing turned off, of course).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top