Legacy GM depth ordering in oblique progection (n00b)

G

geekdude

Guest
Hi all this is my first real attempt at making a game. Its going to be a puzzle/adventure game that is drawn in a top down oblique perspective. The character moves left right up down instead of at angles like in an isometric game but you can see the left and right walls unlike normal orthographic projection. Here is the website I read to learn about it: https://www.significant-bits.com/a-laymans-guide-to-projection-in-videogames/

and here is a gif of my game in action so far: https://twitter.com/GeekdudeAndrew/status/892215073082671104

My character needs to be able to not only go infront of and behind objects but also to the left or right of them. specificaly the character should be drawn infront of objects to their left and under objects to their right. There is very little I can find specifically about using oblique perspective with gamemaker. I found a site that told me for isometric games you use depth=-x-y but I cant seem to get it to work. perhaps that is specific to isometric games?

also I am using tiles for the floor and walls. I have half a mind to switch over to objects because It would be faster to mock up new levels. I wouldnt have to go in and put collision objects in. but right now im trying to find out if I can to set the depth of the tiles in code so my charicter can interact with the walls correctly. next thing i was going to do is to program it to read out the physical coordinates of things so i can wrap my brain around what its doing and what I need it to do but that is for another day. I was wondering if in the meantime anyone had any ideas as to how I can go about solving these problems?
 
G

geekdude

Guest
turns out I cant add links yet and the animated gif is too large. Here is a picture to show you what i am talking about. If you want I can make a gml progect with placeholder sprites but right now i am going to bed.
 

Attachments

G

geekdude

Guest
This is where I am at right now in tackling this game: I converted my tile walls to objects. I am using depth=(x/16)-(y/16) to set the depth of the objects. The characters depth is set by: depth=floor((phy_position_x / 16)-(phy_position_y / 16)); . 16 px is the tile height I am working with. I ended up flipping each wall horizontally so it will fit the numbers. If the character is to the south (bottom) or west (left) of the tiles the depth is lower and so it correctly draws the character over the wall but when the character is to the north (top) or east (right) of the walls the depth shoucl be higher and he should be drawn behind the walls but he pops in and out from behind the walls. This problem seems to stem from the fact that when the character Is walking behind the wall he is actually walking in the same tile. and as he travels along the wall the number changes. I may have to rethink the whole thing.
1.JPG 2.JPG 3.JPG
 

Attachments

CMAllen

Member
The control you are seeking is
Code:
depth=-y;
The depth property is essentially an array of every active object in the room, sorted in descending value (a lower depth object draws after objects with higher depth values). So by assigning an object a depth of its -y value, objects that are lower on the screen are drawn after objects that are higher on the screen, thus simulating (rather easily) the oblique perspective. Note that while the depth property is deprecated in Studio 2, it is still functional.

That being said, you can take control of this on your own and create a ds_grid of all your draw calls, sort them by their -y values and run down that list.
 
G

geekdude

Guest
From what I understand depth= -y is used for games that are drawn in a perspective in which you cant see the sides of walls that run north-south. This way the only thing you need to worry about is if the character is above or below the wall in one direction (top to bottom). It does look like a much easier way to do things but I have drawn my tiles so that you can see the left and right walls. I expect the character to also be able to be in front or behind walls that run north-south as well as walls that run east-west. I have contemplated switching the way tiles are ordered based on weather the character is next to a north-south (depth=-x) or east-west wall (depth=-y) but this seems like it would be inefficient.
I just tried depth=-y anyways and it didnt work quite right.
 

Attachments

CMAllen

Member
Keep in mind that the y position, in terms of the correct draw depth, also needs to take into account its origin point. The origin point of a sprite offsets where the sprite gets drawn. So an origin point at the top of a given sprite will draw at the wrong depth next to a sprite that has its origin point at the bottom. So when you set up the origin points of your sprites, keep in mind how they 'stand' so that everything is standing at the correct and equivalent depth.

And the depth property is simply a draw-call sorting method built into GM. It can be used for any derivation of that purpose. The -y trick sorts objects based on their y position in the active room. You could do -x-y to sort them from top to bottom, left to right, like reading from a book. Of course, given that the same depth is achieved as you move diagonally across the room space, you would probably want to add a multiplier to the value of an object's y position so that each interval of y is greater than the number of x intervals across the screen. You could also have your wall objects get the position of the player object and use that as a center point, so that objects on the same y plane but left or right of the player always draw after the player like thus (pretty sure I've got the math right-ish, but it's just off the top of my head):
Code:
depth=-y-(abs(obj_player.x - x)*-1)
 
G

geekdude

Guest
Hey guys sorry I got busy with other stuff. Had to fix my bicycle before the eclipse. You would not believe how much time it takes to straighten a bike wheel. anyways,

icuurd12b42: your code is interesting. I hadnt thought of approaching it from that angle before. However I was not able to find the view_center function. There is a window_get_x and window_get_y function but point_distance for me is not accepting them as inputs. I was able to use 0,0 though but that kind of does the same thing. here is my code: depth =point_distance(0, 0, x,y); it is still popping in and out from under my tile objects. I will make sure to keep point_distance in mind though. it might come in handy.

Cmallen: I was not able to get depth=-y-(abs(obj_player.x - x)*-1) to work at all. he just goes under the objects all the time. I have tried using depth=(x) and depth=(x-y) for the player.

I have also tried multiple origin points for both player and wall objects.

anyways I have decided to go a different direction. I am going to make the walls depth ordered differently based on which direction the walls go. so north-south walls are allways going to be ordered based on the x coordinate and east-west walls are allways going to be based on the y cordinate. The player character or anything else that is moving will change between depth ordered by Y and depth ordered by x based on which wall they are next to, or in other words which wall object they are intersecting with the bounding box of. If an object is moving its coordinates and depth will be changing anyways so probably not as much overhead as I thought. This way all straight walls will have the same depth across a wall and I wont get the popping over and under parts of the wall as a player travels along it. this has helped me to organize my thoughts and figure out what to do. Thanks.
 
Top