2D & Sprites placement

Hello everyone,

First time I try a project (for fun), in 2D with UE4.

There is something I don’t understand…how can I do in order to have a sprite who appear behind the player when the player is in front of it, and in front of the player, when the player is behind the sprite ?

In order to take thoses pictures, I’ve manualy moved the height of the sprite.

Please tell me if more information are needed…
Thanks a lot for help !

One way would be to separate your lamp into two parts/tiles. The lower part with the collision stays on the background layer, which is drawn behind the player sprite, while the upper part wanders into a foreground layer, which will be drawn above the player.

Then it should be just a matter of scaling them correctly in relation to your player sprites. F.E. your lamp is two tiles high, then your player should also be two tiles high. With that you could apply collision only to the lower player body part (f.e from hips to feet), while the upper body part gets no collision, and would be allowed to be drawn on top of all things on the background layer and covering them, because it does not collide with them. It would be important to make sure, that the lower part of your lamp (that has the collision) is as big/high as the whole upper body part of your player (that part, that has no collision), to ensure, that the players head cannot reach into the area of the upper lamp region (that is in the foreground layer), if the player stands below the lamp.

The feet/lower body would collide with the lower part/lower tile of your lamp (or everything with collision), but the head would be drawn on top of it, cuz no collision.
As soon as your player goes “above” the lower lamp part, it gets covered by the upper lamp part, that is placed in the foreground layer. And since both just have collisions for their feet, it should also prevent wrong drawing orders, since your players lower body part cannot be in the same place as your lower lamp part with it´s collision box.

You can also set the “translucency sort priority” of your sprites. I already noticed that a sprite can be rendered beneath an other one whereas it is physically above. They all have the same priority by default.

1 Like

Thanks a lot @Suthriel & @Grot13 for your help !!
Sorry for late response I was in vacation.

This is a secondary project, so I will take time to test & answer here I think in a few days !

Since i played with 2D Sprites and Tilesets for myself at the weekend, here is how my described version with separation into background and foreground can look like:

I used UE4s Paper2D and followed this tutorial:

i just changed the Paper2D sprite materials from an unlit to a lit version (and let them cast shadows), and added an emissive slider for making it visible even when no light is nearby. Thats why the lights affect the background. Just have to figure out, how to let the player sprites cast shadows too.

2 Likes

Thanks a lot for sharing this beautiful work you’ve made !
I’ll take a deeper look during the wk :slight_smile: