Legacy GM Move collision problem

grossik

Member
Hi
I create collision map by this code:
Code:
global.mapsize=floor(room_width/32)*floor(room_height/32);

for( yy=0;yy<room_height;yy+=32)
{
    s="";
    for( xx=0;xx<room_width;xx+=32)
    {
        i = (xx/32)+((yy/32)*(room_width/32));
        global.map[i]=-1;
        t = tile_layer_find(10,xx,yy);
        if( t>=0 )
        {
            s = s+"1";
            left = tile_get_left(t);
            show_debug_message(left);
            global.map[i]=left/32;          
        } else {
             s = s+"_";      
        }              
    }  
}
And my movement is this:
Code:
var xx,yy,c1,c2;
y = y+grav;
grav+=0.335;
if( grav>=10 ) grav=10;
if( grav<0 )
{
    if( dir=1){
        sprite_index = jump_right;
    }else{
        sprite_index = jump_left;
    }
    c2 = -1;
    c1 = GetCollision(x,y);
    if( (x&$1f)>0 ) {
        c2=GetCollision(x+32,y);
    }
   
    if( c1>=0 || c2>=0 )
    {
        grav=0;
        y = (y&$ffffffe0)+32;
    }
} else{
    if(jump) {
        if(dir=1){
            sprite_index = fall_right;
        } else {
            sprite_index = fall_left;
        }   
    } else {
        grav=0;
        jump=true;
    }
    c2 = -1;
    c1 = GetCollision(x,y+32);
    if( (x&$1f)>0 ) {
        c2=GetCollision(x+22.5,y+32);
    }
           
    if( c1>=0 || c2>=0 )
    {
        y = (y&$ffffffe0);
        grav = 0;
        jump=0;
       
        if( dir=1){
            sprite_index = walk_right;
        }else{
            sprite_index = walk_left;
        }           
    }
}   
if(keyboard_check(vk_left))
{
    dir=-1;
    if(!jump){
        sprite_index = walk_left;
    }
    x=x-xspeed;
    c2=-1;
    c1 = GetCollision(x,y);
    if( (y&$1f)>0 ) c2=GetCollision(x,y+32);
    if(  c1>=0 ) || ( c2>=0 )
    {
        x = (x&$ffffffe0)+32;
    }   
} else if(keyboard_check(vk_right)) {
    dir=1;
    if(!jump){
        sprite_index = walk_right;
    }
    x=x+xspeed;
    c2 = -1;
    c1 = GetCollision(x+32,y);
    if( (y&$1f)>0 ) c2=GetCollision(x,y+32);
    if(  c1>=0 ) || ( c2>=0 )
    {
        x = (x&$ffffffe0);
    }   
} else {
    image_index =0;
}
And script GetCollision
Code:
if( argument0>=room_width ) return -1;
if( argument1>=room_height ) return -1;
if( argument0<0) return -1;
if( argument1<0) return -1;

var xx,yy;

xx = floor(argument0/32) + (floor(argument1/32) * floor(room_width/32));
if( global.mapsize<xx ) return -1;
return global.map[ xx ];
The problem comes when I jump and try to move against the wall.
Like this:

I want the keyboard_check(vk_right) to behave the same as the keyboard_check(vk_left).
 

grossik

Member
If I replace
Code:
    dir=1;
    if(!jump){
        sprite_index = walk_right;
    }
    x=x+xspeed;
    c2 = -1;
    c1 = GetCollision(x+32,y);
    if( (y&$1f)>0 ) c2=GetCollision(x,y+32);
    if(  c1>=0 ) || ( c2>=0 )
    {
        x = (x&$ffffffe0);
    }
to
Code:
    dir=1;
    if(!jump){
        sprite_index = walk_right;
    }
    x=x+xspeed;
    c2 = -1;
    c1 = GetCollision(x+32,y);
    if( (y&$1f)>0 ) c2=GetCollision(x+32,y+32);
    if(  c1>=0 ) || ( c2>=0 )
    {
        x = (x&$ffffffe0);
    }
https://imgur.com/flqWBuE
 
Last edited:
Top