Windows check if player is below object?

K

kingjohnc19

Guest
So I'm making a top-down RPG and I'm trying to make a tree object. Is there a way to detect whether the player is above or below this object, and change the depth based on this?
 
If it's top-down, then simply draw the trees after the player object (and anything that would be considered on the ground, or at least below the tree height). There's no need to go fiddling around with depths and such if you just structure your pipeline to account for these things, I can't speak for layers or anything as I'm used to either GM's old depth system or manually drawing things.

If the player can actually go above the trees, then that's a slightly different story.
 

woods

Member
i remmber somewhere a few years back... in the step event for (all your objects i think) you would put in this line..

depth =y-1

or depth =-y

i cant remmber which.. but basically is this.. when your player moves north far enough to be behind the tree.. the tree has a higher depth than the player.. so the player appears drawn behind the tree..

hope this helps
 

PlayerOne

Member
You could do something like this in the tree object with the sprite centered.

Code:
if obj_player.y>y{depth=10} // Below player object
else{depth=-10} // Above player object
I think I might have the dpeth values mixed up but this should work.
 

TheouAegis

Member
You could do something like this in the tree object with the sprite centered.

Code:
if obj_player.y>y{depth=10} // Below player object
else{depth=-10} // Above player object
I think I might have the dpeth values mixed up but this should work.
Would only be feasible if no other instances are moving around.

In GMS1 or GM8, depth=-bbox_bottom works just fine.
 

TheouAegis

Member
I can't stand GMS2, since depth and layer handling is so different, I guess you could try to do what they did in RPG Maker. You have a layer for all the tiles that are at the same level as a player, which will always draw below the player, and you have another layer for overhead tiles which were always drawn above the player.
 
Last edited:

JasonTomLee

Member
I can't stand GMS2, since depth and layer handling is so different, I guess you could try to do what they did in RPG Maker. You have a layer for all the tiles that are at the same level as a player, which will always drop below the player, and you have another player for overhead tiles which were always drawn above the player.
Lol tell me about it.. the new layers are a pain to get adjusted to. But the method you just mentioned seems to be the way to go!

Tile Layers --> Game Layers ( Entity, FX, etc.. ) ---> Foreground Layer
 
Top