• 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!

[Solved] Top-Down Adventure Depth Problems

K

Kerberos

Guest
Hey, guys! First of all sorry for my bad English, I hope you can understand everything :)
I am working on a Top-down game similar to Alundra:
.
The player and other instances are able to jump on other objects and platforms. Everything works with collision masks and with the function "place_meeting".
I invested so much time to implement this features but it still doesn't work very well. Every instance has following variables:
  • jump (the truth value decides whether the object jumps or not)
  • z (the z-axis)
  • z_ground (the height of the object under this instance)
  • height (the height of the object)
  • z_speed (speed for the jump)
So, I have the problem that I don't know exactly how to define the depth of the objects. First I thought "depth=-y-z_ground" was a good solution but when the player is in front of stacked objects and he starts jumping this happens: https://dl.dropboxusercontent.com/s/xhb2oirccv9mvb3/Help.png?dl=0
Do you have any ideas how I can define the depth properly?

Regards,
Kerberos.
 
Last edited by a moderator:
A

anomalous

Guest
Perhaps when you jump, the depth of the player should change based on jump height.
 
K

Kerberos

Guest
Thanks for the quick reply! I already tried to change the depth based on the z axis. You mean "depth = -y-z" right? But this also causes a problem. When the player jumps behind the objects, his depth gets too low and he is displayed over the objects. Like this: https://dl.dropbox.com/s/grizy052j6eeozk/Help2.png?dl=0
 
Last edited by a moderator:
T

TheMatrixHasMe

Guest
I don't understand why you are using z axis, isn't z axis basically depth? I thought z axis was used for 3d games but the game you are showing looks 2d.
 
K

Kerberos

Guest
Every instance has the variable called "z" to create a fake 3d effect. It contains the current height of the objects. The objects are drawn like this: "draw_sprite(sprite_index, image_index, x, y-z)".

Thanks for your reply! :)
 

RangerX

Member
I know its not your direct answer but an alternate solution could be the jump being an animation and then your Y position does't change...
 
D

Docker

Guest
nvm that won't work, ill have a think and re-edit this...
 
Last edited:
K

Kerberos

Guest
I know its not your direct answer but an alternate solution could be the jump being an animation and then your Y position does't change...
How do you mean that exactly? "z_ground"(the ground under the object) and consequently the depth would still change.
 
Last edited by a moderator:
B

Blazing

Guest
Is there a way you could calculate the depth value from his shadow? That might fix the issue. Then no matter how high he jumps, his depth is according to the ground under him and not how high he is in general.
 
M

maartenvt

Guest
The easiest I can think of to implement a z-axis in a birdview/isometric game as yours, is giving every object a custom variable 'z' to indicate it's vertical position. The object draws itself on (x,y-z). The depth should always remain -y, the z-component does not matter for the depth. Think of it this way: Imagine you take the cross section along the y- and z-axis. Then the camera would be placed like this:



Now the depth of each object says something about which one is drawn first, i.e. the object with the highest depth should be drawn first, then object with the second highest depth on top of that and so on...
Note that it does not matter at all what the Z coordinate is. You want to draw the objects that are furthest away (along the y axis) first, in this case 1, 2 and then 3. Due to the direction of the y-axis in game maker, this is done by making the depth of each object -y.
 
Last edited by a moderator:
K

Kerberos

Guest
Well, that's a very nice solution I didn't think of that! Thank you :D I only have the issue that the player is still drawn behind the objects, although he is on top, because -y doesn't consider the z-value in that case. Do you have any idea to fix that?
 
M

maartenvt

Guest
Is your character actually on top of the wall object, or behind it? Let me ask you a question, what do you think the (x,y,z) coordinates of you character should be when it is on top of the wall (A) and when it is behind the wall (B) (I don't mean exact coordinates, just how A and B would be different)?
 
K

Kerberos

Guest
The player is actually on top of the wall object in the example. (A) When the player is on top of the wall object, the z-value changes to the height of the wall object because his collision mask overlaps with the collision mask of the wall object. (B) When the player is behind it, the z-value is 0 because the collision masks aren't overlapping anymore.
Here is a little comparison:

Thanks! :)
 
M

maartenvt

Guest
Right, in that manner! I was wondering if you understood the fact that you can think about the model of the world (a 3 dimensional one) and the visualization (2 dimensional) of that model separately, and it seems you do :)

Ok, so the problem here seems to be the way the origins of your sprites are placed. Think about when the player should be drawn behind the walls and when it should be drawn over the walls. Then adjust the position of the origins of your wall and player sprites accordingly! (hint: reason about the edge case in which the player is standing on top of the wall on the very edge almost falling of the wall (the edge with the lowest y-value))
 
K

Kerberos

Guest
To be honest I use the top of the collision mask (bbox_top) instead of the origin but I'll try to adjust that. Thank you very much! :D

Edit:
I changed the depth of the player with adjusting the origin and it works very well. Thank you so much for your help! :)
 
Last edited by a moderator:

Pkirkby

Member
To be honest I use the top of the collision mask (bbox_top) instead of the origin but I'll try to adjust that. Thank you very much! :D

Edit:
I changed the depth of the player with adjusting the origin and it works very well. Thank you so much for your help! :)
I see you got this to work, care to share how you did it. I currently am attempting this too.
 
A

atmobeat

Guest
I'm working on a way to deal with depth-sorting for tiles as well. It isn't simple but I think a lot of people making top-down games with multiple height levels and jumping will like it.
 
K

Kerberos

Guest
@Pkirkby
Unfortunately, I found out that the solution didn't work quite well. At first I thought it worked but after testing it with more objects etc. I got problems again. Just shifting the origin isn't enough and this is actually logic. Currently, I am considering to share my newest approach on sorting depth in a 2.5D Top-Down-Game. If you don't want to wait you can try this method: https://www.yoyogames.com/blog/458/z-tilting-shader-based-2-5d-depth-sorting by Ariak. It uses the 3D-Mechanics of Game Maker and is quite easy to implement.
 
Top