[Solved] Top-Down Adventure Depth Problems

Discussion in 'Programming' started by Kerberos, Jan 31, 2017.

  1. Kerberos

    Kerberos Member

    Joined:
    Jan 31, 2017
    Posts:
    18
    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: Feb 3, 2017
  2. anomalous

    anomalous Member

    Joined:
    Jun 29, 2016
    Posts:
    464
    Perhaps when you jump, the depth of the player should change based on jump height.
     
  3. Kerberos

    Kerberos Member

    Joined:
    Jan 31, 2017
    Posts:
    18
    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: Feb 1, 2017
  4. TheMatrixHasMe

    TheMatrixHasMe Member

    Joined:
    Jun 22, 2016
    Posts:
    176
    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.
     
  5. Kerberos

    Kerberos Member

    Joined:
    Jan 31, 2017
    Posts:
    18
    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! :)
     
  6. RangerX

    RangerX Member

    Joined:
    Jun 20, 2016
    Posts:
    2,596
    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...
     
  7. Docker

    Docker Member

    Joined:
    Aug 31, 2016
    Posts:
    122
    nvm that won't work, ill have a think and re-edit this...
     
    Last edited: Feb 1, 2017
  8. Kerberos

    Kerberos Member

    Joined:
    Jan 31, 2017
    Posts:
    18
    How do you mean that exactly? "z_ground"(the ground under the object) and consequently the depth would still change.
     
    Last edited: Feb 3, 2017
  9. Blazing

    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.
     
  10. maartenvt

    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:

    [​IMG]

    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: Feb 4, 2017
  11. Kerberos

    Kerberos Member

    Joined:
    Jan 31, 2017
    Posts:
    18
    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?
    [​IMG]
     
  12. maartenvt

    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)?
     
  13. Kerberos

    Kerberos Member

    Joined:
    Jan 31, 2017
    Posts:
    18
    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: [​IMG] [​IMG]
    Thanks! :)
     
  14. maartenvt

    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))
     
  15. Kerberos

    Kerberos Member

    Joined:
    Jan 31, 2017
    Posts:
    18
    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: Feb 4, 2017
    atmobeat and (deleted member) like this.
  16. Pkirkby

    Pkirkby Member

    Joined:
    Mar 25, 2019
    Posts:
    115
    I see you got this to work, care to share how you did it. I currently am attempting this too.
     
    atmobeat likes this.
  17. atmobeat

    atmobeat Member

    Joined:
    Feb 24, 2017
    Posts:
    45
    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.
     
  18. Kerberos

    Kerberos Member

    Joined:
    Jan 31, 2017
    Posts:
    18
    @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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice