• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker [SOLVED] Tileset Slopes

N

nickvm98

Guest
I'm making a 2D platform that uses a solid/tile-slope. The Player can hit solids as well as behave similarly to the method used in Shaun Spaldings Tile Based Platformer video, link here :

Note: Solids aren't used for slopes or the floor.

I've watched this man's 50min video to the letter, over and over again and there seems to be a problem with the slope sections of my game.

The first time I load my game the player interacts normally with the tiles of the game but with the slopes, the player doesn't interact with the slopes going up and teleports into the slopes going down. It warps to the very bottom of the slope tile.

The second time I load my game the player interacts normally with the tiles but with the slopes, the player jumps up the tile mask of the slope going up and jumps down to the top of the tile mask going down.

Here's an illustration:
collision.png

Here is every snipet of code relevant to the video:
Code:
//Create
tilew=sprite_get_width(spr_collisionsheet);
tiles=tilew/30;
var layerid=layer_create(0,"Tiles");
tilemapid=layer_tilemap_create(layerid,0,0,ts_collisionsheet,tiles,1);
for(var _i=0;_i<=tiles;_i++) {tilemap_set(tilemapid,_i,_i,0)};

//Draw
draw_tilemap(tilemapid,0,0);
for(var _i=tilew-1;_i>=0;_i--){
    var _check=0;
    while(_check<=30) {
        global.heights[_i]=_check;
        if _check==30 {break};
        if surface_getpixel(application_surface,_i,_check)!=c_black {break};
        _check++
        }}
    room_goto_next();
Code:
//Returns if position is below floor height of given tile. Returns depths.
///@param tilemap
///@param x
///@param y
var _pos=tilemap_get_at_pixel(argument0,argument1,argument2);
if _pos>0 {
    if _pos==1 {return argument2 mod 30};
    var _thefloor=global.heights[(argument1 mod 30)+(_pos*30)];
    return ((argument2 mod 30)-_thefloor);
    }
else {return -(30-(argument2 mod 30))};
Code:
//Create
tilemap=layer_tilemap_get_id("Collision");

//Step
//Var
var _p1,_p2,_bbox_side;
var last_power;
var _ax=(keyboard_check(key_right)-keyboard_check(key_left));
var solid_ground=place_meeting(x,y+1,obj_wall);
var tile_ground=(scr_infloor(tilemap,x,bbox_bottom+1)>=0);
var _water=0;
var _climb=0;
var spr_width=sprite_get_width(sprite_index);
var spr_height=sprite_get_height(sprite_index);

//States
if solid_ground or tile_ground or (scr_infloor(tilemap,bbox_left,bbox_bottom+1)>=0) or (scr_infloor(tilemap,bbox_right,bbox_bottom+1)>=0) {
    if round(xvel)!=0 {obj_player.state=state.move} else {obj_player.state=state.stand};
}
else {obj_player.state=state.jump};
//Motion
if obj_player.state=state.stand {
        xvel=scr_approach(xvel,_ax*(20+keyboard_check(key_run)*6),0.4);;
        yvel=keyboard_check_pressed(key_jump)*-14;
        if keyboard_check_pressed(key_jump) {
            tile_ground=0;
            audio_stop_sound(sfx_jump);
            audio_play_sound(sfx_jump,50,0);
        }
    };
if obj_player.state=state.move {
        xvel=scr_approach(xvel,_ax*(4+keyboard_check(key_run)*6),0.7);
        yvel=keyboard_check_pressed(key_jump)*-14;
        if keyboard_check_pressed(key_jump) {
            tile_ground=0;
            audio_stop_sound(sfx_jump);
            audio_play_sound(sfx_jump,50,0);
        }
    };
if obj_player.state=state.jump {
        yvel+=0.65;
        xvel=scr_approach(xvel,_ax*(4+keyboard_check(key_run)*6),0.4);
}

//Collision
xvel+=xvel_fraction;
xvel_fraction=xvel-(floor(abs(xvel))*sign(xvel));
xvel-=xvel_fraction;
xvel=median(-24,xvel,24);
//Tile
if xvel>0 {_bbox_side=bbox_right} else {_bbox_side=bbox_left};
_p1=tilemap_get_at_pixel(tilemap,_bbox_side+xvel,bbox_top);
_p2=tilemap_get_at_pixel(tilemap,_bbox_side+xvel,bbox_bottom);
if (tilemap_get_at_pixel(tilemap,x,bbox_bottom)>1) {_p2=0};
if (_p1==1) || (_p2==1) {
    if xvel>0 {x=x-(x mod 30)+(30-1)-(bbox_right-x)};
    else {x=x-(x mod 30)-(bbox_left-x)};
    xvel=0;
}
//Solid
if xvel!=0 {
    if place_meeting(x+xvel,y,obj_wall) {
        repeat(abs(xvel)) {if !place_meeting(x+sign(xvel),y,obj_wall) {x+=sign(xvel)} else {xvel=0 break}};
        };
    else {x+=xvel};
    };
 
yvel+=yvel_fraction;
yvel_fraction=yvel-(floor(abs(yvel))*sign(yvel));
yvel-=yvel_fraction;
yvel=median(-24,yvel,24);

//Tile
if(tilemap_get_at_pixel(tilemap,x,bbox_bottom+yvel)<=1){
if yvel>=0 {_bbox_side=bbox_bottom} else {_bbox_side=bbox_top};
_p1=tilemap_get_at_pixel(tilemap,bbox_left,_bbox_side+yvel);
_p2=tilemap_get_at_pixel(tilemap,bbox_right,_bbox_side+yvel);
if (_p1==1) || (_p2==1) {
    if yvel>=0 {y=y-(y mod 30)+(30-1)-(bbox_bottom-y)};
    else {y=y-(y mod 30)-(bbox_top-y)};
    yvel=0;
}}
var _floordist=scr_infloor(tilemap,x,bbox_bottom+yvel);
if _floordist>=0 {
         y+=yvel;
         y-=(_floordist+1);
         yvel=0;
         _floordist=-1;
    }

//Solid
if yvel!=0 {
    if place_meeting(x,y+yvel,obj_wall) {
        repeat(abs(yvel)) {if !place_meeting(x,y+sign(yvel),obj_wall) {y+=sign(yvel)} else {yvel=0 break}};
        };
    else {y+=yvel};
    };

//Tile - Slopes
if tile_ground {
    y+=abs(_floordist)-1;
        if ((bbox_bottom mod 30)==(30-1)) {
            if (tilemap_get_at_pixel(tilemap,x,bbox_bottom+1)>1){
            y+=abs(scr_infloor(tilemap,x,bbox_bottom+1))
            }
        }}
if !place_meeting(round(x),round(y),obj_wall) {x=round(x) y=round(y)} else {x=round(x)-sign(xvel) y=round(y)-sign(yvel)};

I honestly don't understand the problem I'm having and I've checked the code over and over again but the problem still occurs. Can someone please tell me what's the issue?
 
Last edited by a moderator:
N

nickvm98

Guest
Just reposting since the issue hasn't been fixed. This really halts the progression of my game.
 
Top