• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Depth &"Floating" Shadows (2.5D)

Spam1985

Member
Hi there. I'm making a top-down 2.5D game with the ability to jump on top of objects.
This is all working quite well mechanically, but aesthetically I have 2 problems:

(This is an image from "The Chaos Engine" to demonstrate the kind of perspective I am using. It's basically a 50/50 between top view and side view)...


-When the player is standing on top of an obstacle, let's say a box, his shadow sprite will clip over the edges of the obstacle, "floating" in the air unnaturally. Is there a good solution for this?

-Depth is sorted in the typical way (depth =-y) but this causes problems when the player is standing on top of objects. As an example, let's say there are two adjacent boxes on the Y axis. The player is standing on the top box, but as the bottom box has a higher depth, it is drawn over parts of his sprite. What is the best depth solution here?

Thanks for taking the time to read this and I truly appreciate any help you can give me.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
-When the player is standing on top of an obstacle, let's say a box, his shadow sprite will clip over the edges of the obstacle, "floating" in the air unnaturally. Is there a good solution for this?
Draw shadows for all game objects from a controller object with higher depth.

-Depth is sorted in the typical way (depth =-y) but this causes problems when the player is standing on top of objects. As an example, let's say there are two adjacent boxes on the Y axis. The player is standing on the top box, but as the bottom box has a higher depth, it is drawn over parts of his sprite. What is the best depth solution here?
"depth = -y" is a very misleading concept. Past some point, it becomes easier to use a 3d orthographic projection with a 45-degree angle (while applying a XYZ=(1,sqrt(2),sqrt(2)) scale) so that you can draw flat floor/wall planes with d3d_ functions or vertex buffers.
 

Spam1985

Member
Hi Yellow, thanks the response. If messing with 3D is my best bet, then I think I'll just continue using my flawed system. (3D stuff just baffles and confuses me no end, and the documentation doesn't explain it well enough for me).

As for the shadows, I guess I didn't explain the problem very well (it's kinda difficult to explain but I'll try). The shadow is a sprite under the player. If the player is standing on top of a box, for example, then the shadow sprite should be restricted in how it is drawn so that it can only be drawn on the surface of the box, but as it is, the sprite won't care that it is defying the laws of physics and will be drawn on both the box and "thin air" (going over the edges).

I was thinking I could check the z value for every pixel of the shadow but that sounds like a bit of a nightmare.
 

Spam1985

Member
Well I think my best bet with the shadows is to learn about surfaces... hopefully I can get them working in 3D if only I could get 3D to work first....

I've tried switching to a 3D orthographic projection. Everything is upside-down and there is scaling going on, which is unwanted. And the mouse cursor is AWOL. I just need it to look as it did before but make use of the 3D depth.

a 3d orthographic projection with a 45-degree angle (while applying a XYZ=(1,sqrt(2),sqrt(2)) scale) so that you can draw flat floor/wall planes with d3d_ functions or vertex buffers.
...and I think this is the solution if only I could understand it. "applying a XYZ=(1,sqrt(2),sqrt(2)) scale)"????? Please could somebody explain how to do this?
Right now it's:
d3d_set_projection_ortho(view_xview, view_yview, view_wview, view_hview, 45);

Which is obviously not correct.

EDIT: Long story short, I need to calculate 3D depth in a 2D game.
 
Last edited:

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
...and I think this is the solution if only I could understand it. "applying a XYZ=(1,sqrt(2),sqrt(2)) scale)"????? Please could somebody explain how to do this?
Right now it's:
d3d_set_projection_ortho(view_xview, view_yview, view_wview, view_hview, 45);

Which is obviously not correct.
In GMS1 it would be d3d_set_projection (to give it a 45-degree look angle from -Y+Z), d3d_set_perspective (to disable perspective for point-to-point projection), and d3d_transform_ (to do the actual scaling). Might be able to utilize matrix_set and related to give it a custom projection instead of doing d3d_set_projection + d3d_transform_, but I only worked with matrices in GMS2

As for the shadows, I guess I didn't explain the problem very well (it's kinda difficult to explain but I'll try). The shadow is a sprite under the player. If the player is standing on top of a box, for example, then the shadow sprite should be restricted in how it is drawn so that it can only be drawn on the surface of the box, but as it is, the sprite won't care that it is defying the laws of physics and will be drawn on both the box and "thin air" (going over the edges).
Yeah, that would be... fun. With 3d you could use something like this, or similar approaches that can take advantage of you being able to draw geometry in arbitrary order
 

Spam1985

Member
Thanks Yellow, I really do appreciate you trying to help me, but...

...unfortunately there is just way too much I don't understand here. I've tried setting it to 3D and everything is upside-down. The mouse cursor cannot be seen, and none of the sprites are drawn. On top of that, I don't know where to set everything (I've got the d3d_set_prespective in draw and the others in create... no idea if that is right... not to mention I don't know how to set the camera to exactly mimic what I had already in 2D).

I hate 3D.

I wonder if there is some formula I can use to calculate 3D depth in 2D? Maybe something can be done with lengthdir? I don't know.

EDIT: For depth I've made up some ridiculous convoluted formula that works for what I need (as long as the obstacles are no taller than 32 pixels).

As for shadows, I'm not there yet. I'm sure the answer lies in surfaces... never used them before but I guess it's time to figure them out.

Can be considered cased closed for now.
 
Last edited:
Top