GameMaker Detecting Tiles

Dead Eye

Member
Hello everyone and thank you for your help!
So this one is simple, I have a racing game and I want to detect if the object is in a collision with the road or the ground (goes slower on the ground and faster one road). What command would I use to do this? This is what I've tried.
Code:
if tilemap_get_at_pixel(ground,x,y)
top_spd = 4
else if tilemap_get_at_pixel(road,x,y)
top_spd = originalspeed
However, it isn't detecting it. Any help would be apreciated,
thanks again.
 

Miradur

Member
Hi, try this little code from Mike(from Blood Money Remake):

Code:
// Create Event
GroundLayer =  layer_tilemap_get_id("layer_Ground")   // take the ID from Groundtile-Layer

// Step Event
    if (xx & 31) == 0 && (yy & 31) == 0 {
        var t  =  tilemap_get_at_pixel(GroundLayer, xx, yy) & tile_index_mask
    
        if (t != 0) {
            top_spd = 4    // we are on the ground
        } else {
                top_spd = originalspeed
                }
    }
This is for 32 x 32 tiles, if you have 16 x 16, then take &15(instead of 31).

Miradur
 

Dead Eye

Member
Thank you both!
Turns out the road was on top of the grass so it just slowed down because it read was on the ground.
Just removed the ground under the road and it worked.
 
Top