[Solved]ds_grid collision with layered tiles.

B

Blaize

Guest
I've recently adapted a Heartbeast tutorial for something I'm working on (here's the original) on grid collisions.

It works as far as collision checking goes, but my tiles in the room are layered so that I can get some illusion of depth.
Tile depth looks like (note that the OWorldCell is a macro):
Code:
for (yy=0;yy<h;yy++)
{
    for (xx=0;xx<w;xx++)
    {
        var visualTiles = tile_layer_find(999998,xx*OWorldCell, yy*OWorldCell);
        if (visualTiles)
        {
            tile_set_depth(visualTiles,-yy*(OWorldCell));
        }
    }
}
and player depth (in the step event) looks like:
Code:
depth = floor(-y);
This is the result:
Bug_001a.jpg

If you look at A, the player object puts itself 1px into the next grid space which means that it will draw above the environment tile. The weird thing is it only happens occasionally since in B it's behaving just how I want it to be.

What's up with it?
 

Attachments

TheouAegis

Member
Where is the origin of the player sprite? Your tiles are at (0,0), so if the player is not at (0,0) also, then the player's depth will be lower than it should be.

depth = floor(sprite_yoffset - y);

Maybe try that in the player.
 

slayer 64

Member
You could change the origin of your sprite in the player, or increase the depth more. I'm not sure you need to floor() the y value.
Code:
depth=-y+16
 
B

Blaize

Guest
Just changed the origin of the sprite and of course that was it. I always seem to forget that the count starts from 0.
Thanks!

I'm not sure you need to floor() the y value.
You're right, it's not needed - that's just me being paranoid about real numbers.
 
Top