Rendering order of multiple entities of the same layer

I have a Ball that is made out of multiple entities/pieces so it can “explode” when losing the game.

I want the Ball to always be in the foreground since it’s destroying some platforms that fly away and they obscure the vision if they happen to fly in front of the ball.

I can make it so the Ball is in the foreground (layering + disabling depth test), however, when I do that the pieces of the ball interfere with each other and I can see the pieces in the back through the pieces in the front.

Got any ideas how to solve this?

It is a bit of a kludge, but maybe you can make the ball smaller and place it closer to the camera so it appears to be the same size. This should reduce the chances of the other pieces flying in front of the ball.

Have you tried using Particle systems for the explode function instead @Helldubs?

This approach is sadly not possible since the view of the game is from the side. Making the ball smaller and the camera closer to the ball would make the whole fov wrong.

This might be a possible solution, although since I already have the Ball cut to pieces I thought I could use the work that I’ve already done. It’s not necessary though, so I am willing to try to do it with a particle system. To implement that I’d have to change the color of the particle system to fit the color of the ball (which is always changing), though. I know there is a way to change the color of the particle system via code but I couldn’t figure it out by myself yet. Would you or someone else mind giving a code example how to change the color of the particle system?

I think you can do this with multiple layers and multiple cameras.

One camera for the main scene, and a second one for the ball. The second camera is rendering the layer for the ball only, 2nd in priority and clears the depth buffer.

This thread might help you out.

I tried this but it didn’t work. The end result is the same as before, I can see the pieces through the ball.

I managed to come up with a pretty easy fix myself. I now just have a new sphere that acts as the ball and is disabled on death while the pieces are enabled and fly away.
Thanks for trying to help, anyways :slight_smile:

1 Like

I just remembered this thread where the claim was made that you could put a 3D model into UI space. Perhaps that would work. I do know that 2D elements in UI space will layer over any of the 3D elements in world space. But this isn’t something I’ve tried with 3D models in UI space.

Wats the script for that

Sorry for the late anwser, but if it helps anybody.

this.ball.enabled = false;
for(let index : number = 0; index < this.exploded.length; index++){
             this.exploded[index].enabled = true; //exploded are the different ballparts
1 Like