[SOLVED] Render Object Over Another Objects with one camera

So for the game I am working on I have a crosshair that is always at the spot the players mouse is and I am trying to make where the crosshair is it is always shown.
Like in this post (example) problem is I want to do this with a single camera,help?


The layer I want to overlap the world layer with is “sight”.

you can clear the depth buffer on that overlay layer you have

:sweat_smile: how do you do that?
(if I go silent for a bit I’m transitioning to lunch(high school))

you look at the Layer documentation, and search for clear.

It is possible by setting a layer to clear depth before you render meshes in a layer that you want to render on top of everything else.

I’ve done it in the project here: https://playcanvas.com/project/950571/overview/fps-pit

I’ve made a layer called ‘Clear Depth’ that I set in code to clear the depth buffer.

Code: https://playcanvas.com/editor/code/950571?tabs=95528900

(function() {
    const app = pc.Application.getApplication();
    app.on('start', () => {
        // We have special layer that we want to set so that it clears the depth buffer
        // This helps us render the weapon on top of the world
        const clearDepthLayer = app.scene.layers.getLayerByName('Clear Depth');
        clearDepthLayer.clearDepthBuffer = true;
    });
})();

This means that anything that renders after this layer is going to render over anything that has rendered before.

In my case, the Weapon layer that the gun is on:

1 Like

So I made a clear depth layer and rearranged my layers to fit the way you did it and I got it to work kind of…

so now the crosshair is finally appearing in the scene but it isn’t overlapping when it is on the player or enemy.


Screenshot 2023-01-18 12.25.02 PM
Screenshot 2023-01-18 12.24.57 PM
I know these images are low-quality; :sweat_smile: school computers aren’t the best at running play canvas.
Screenshot 2023-01-18 12.23.48 PM
Screenshot 2023-01-18 12.23.15 PM

I would check the layer order. Are the player and enemy layers before the layer that clears the depth buffer and is the cross hair rendering after that layer

Have you added the clear depth layer to the camera?

If you are still having issues, please post the project link here

:man_facepalming:
I do that :joy:

It works!
Thank you so much