Ground Z position

Hello community!

How should I do to make the character keeps rendered always over the ground in a top-down game and not gets covered by the gound object as soon the character’s Z position is lower than the ground’s Z?

This is the context:
I put a background image in Z: 0, Y: 350
The ground is another plane rotated 90º in Z:350, Y: 0
The character can move freely in the Z and X axis and the camera (normal, not ortho) follows it in an angular position of 30º over his head and a distance of Z - 800 to keep a good view,

Everything looks fine, when the character’s Z is less than other 2D objects over the map it looks above and below when the objects are closer the camer. The big problem is the ground…
when the character is closer than the middle position it is rendered over the ground but when I move it further away passing the half then it gets covered by the ground.
So how should I handle it?

Z-index is usually to maintain keep above 0
(0, 1]
Depend on also camera renderer. Make sure the Z-order for Char > Ground > Background

Thanks for reply!
Yes, all Z orders are above 0.
However if I set char always > ground then I see the char always between the middle of the ground and the lower limit of the map.

Please note that while the sprites are 2D, the map and movement environment are 3D. So I need to keep the char stand on the ground because char-Y is > ground-Y

Is there at least an example of 3D game made in Defold where I can see how this issue has been handled?

It should be simple… if an object is BETWEEN the camera and the background it doesnt matter ONLY the Z axis but also X and Y. Right? Is in the middle. However in this case only matters Z. Why and what can I do in this case? I try to understand it.

Thanks, regards!

Copy-paste sprite.material (do you use sprites?) to your project, rename it to ground.material, open, change the tag to ground. Assign the new material to your ground sprite.

Then copy-paste default.render_script and default.render (change paths in .render file, and game.project to the new render) from built-ins to your project, open it, add new predicate:

    self.predicates = create_predicates("tile", "gui", "particle", "model", "debug_text", "ground")

…and hard-code the order of how ground/tile sprites are drawn:

    render.enable_state(graphics.STATE_BLEND)
    render.draw(predicates.ground, draw_options_world)
    render.draw(predicates.tile, draw_options_world)
    render.draw(predicates.particle, draw_options_world)
    render.disable_state(graphics.STATE_DEPTH_TEST)

P.S. Quick tip - use Ctrl/Cmd+P to quickly navigate the project.

4 Likes

Awesome! Thank you so much aglitchman!!
That worked perfectly :smiley:

I had no idea how the order of materials rendering could be customized, so I also appreciate the teaching and specificity.

2 Likes