I have the sprite sheet animation and movement all working, and I can certainly add in custom game objects which will interact and collide with my player sprite. However, I’m not sure how to work with a static background image. Naturally I’d need to have my player collide with background objects, move behind some objects and in move in front of others etc.
I assume I have to post-crop and separate the image into layers—background and foreground (which could be done in any decent image editing program) and I could manually make sprites with colliders and place them where needed on the image in Unity to inhibit movement. Is this the best way to go about doing this? Any further tips or suggestions?
I’d greatly appreciate any advice or links to get me started on the right path.
One way is to make each element separate from the background and use a layering system. One way is to change sprite z Position depending on Y height, this way you need to script each sprite to offset them in the correct Z position. Problem is if you do stuff like in the example you posted, is a little harder to calculate the eact origin of a sprite without having to subdivide it.
There is another way, but is more complicated and I don’t really know the whole thing. Using a depth texture writing in the depth buffer to get world position of pixels from a heightmap. This way you can have one background image. Is the same technique used in games like Pillars of eternity.
I’m gonna link you some stuff if you want to take a look:
The last method is the most complicated as it require you to know how to write shaders that write in the depth buffer, but I think is the only viable one for one background image vs multiple sprites.
As for collision just use colliders you place them at the base of the object and you are good to go.