GML Enemy climing right walls but not left walls

R

robeng

Guest
Hello! I'm creating a platformer in GameMaker Studio 2. I have a problem that looks like this:
Here is my End Step code that moves my enemy:

Code:
if ( ((oMorot.x-x) < 110) && ((oMorot.x-x) > -110) && ((oMorot.y-y) < 110) && ((oMorot.y-y) > -110)) {
    
    if (place_meeting(x,y,oSlag) && oSlag.slag == -1) {
        hsp = random_range(-3,-6) * walksp;
    } else if (place_meeting(x,y,oSlag) && oSlag.slag == 1) {
        hsp = random_range(3,6) * walksp;
    } else if (x = oMorot.x) {
        hsp = 0 * walksp;
    } else if (x < oMorot.x) {
        hsp = 1 * walksp;
    } else if (x > oMorot.x) {
        hsp = -1 * walksp;
    }
} else {
    hsp = 0;
}
vsp += grv;
if (place_meeting(x,y+1,oWall) && place_meeting(x+1,y,oWall) || place_meeting(x-1,y,oWall)) {
    vsp = -5;
}

//Horisontell collision
if (place_meeting(x+hsp,y,oWall)) {

    while (!place_meeting(x+sign(hsp),y,oWall)) {
        x += sign(hsp);
    }
    hsp = 0;
}
//Vertical collision
if (place_meeting(x,y+vsp,oWall)) {

    while (!place_meeting(x,y+sign(vsp),oWall)) {
        y += sign(vsp);
    }
    vsp = 0;
}

//Moves ENEMY1
x += hsp;
y += vsp;

//Checks ENEMY1 life
if (liv <= 0) {
    
    var randi = random_range(5,1);
    var randi2 = random_range(2, 5);
    
    for (i = 0; i < randi; i++) {
        var rangeX = random_range(-10,10);
        var rangeY = random_range(-10,10);
        instance_create_layer(x+rangeX,y+rangeY,"Coin",oGold);
    }
    for (i = 0; i < randi2; i++) {
        var rangeX = random_range(-11,11);
        var rangeY = random_range(-11,11);
        instance_create_layer(x+rangeX,y+rangeY,"Coin",oEmerald);
    }
    
    instance_destroy();
}
As you might guess, I don't want my enemy to clime right walls.
Thanks in advance!
 
Hello! I'm creating a platformer in GameMaker Studio 2. I have a problem that looks like this:
Here is my End Step code that moves my enemy:

Code:
if ( ((oMorot.x-x) < 110) && ((oMorot.x-x) > -110) && ((oMorot.y-y) < 110) && ((oMorot.y-y) > -110)) {
   
    if (place_meeting(x,y,oSlag) && oSlag.slag == -1) {
        hsp = random_range(-3,-6) * walksp;
    } else if (place_meeting(x,y,oSlag) && oSlag.slag == 1) {
        hsp = random_range(3,6) * walksp;
    } else if (x = oMorot.x) {
        hsp = 0 * walksp;
    } else if (x < oMorot.x) {
        hsp = 1 * walksp;
    } else if (x > oMorot.x) {
        hsp = -1 * walksp;
    }
} else {
    hsp = 0;
}
vsp += grv;
if (place_meeting(x,y+1,oWall) && place_meeting(x+1,y,oWall) || place_meeting(x-1,y,oWall)) {
    vsp = -5;
}

//Horisontell collision
if (place_meeting(x+hsp,y,oWall)) {

    while (!place_meeting(x+sign(hsp),y,oWall)) {
        x += sign(hsp);
    }
    hsp = 0;
}
//Vertical collision
if (place_meeting(x,y+vsp,oWall)) {

    while (!place_meeting(x,y+sign(vsp),oWall)) {
        y += sign(vsp);
    }
    vsp = 0;
}

//Moves ENEMY1
x += hsp;
y += vsp;

//Checks ENEMY1 life
if (liv <= 0) {
   
    var randi = random_range(5,1);
    var randi2 = random_range(2, 5);
   
    for (i = 0; i < randi; i++) {
        var rangeX = random_range(-10,10);
        var rangeY = random_range(-10,10);
        instance_create_layer(x+rangeX,y+rangeY,"Coin",oGold);
    }
    for (i = 0; i < randi2; i++) {
        var rangeX = random_range(-11,11);
        var rangeY = random_range(-11,11);
        instance_create_layer(x+rangeX,y+rangeY,"Coin",oEmerald);
    }
   
    instance_destroy();
}
As you might guess, I don't want my enemy to clime right walls.
Thanks in advance!
I don't have much time to check all your code but,
check if there is not a second wall on top of the first wall.
Jump only if there is 1 block to jump.
 

CloseRange

Member
For future refrence it would be proper to say they are climbing the left wall (becuase in the enemy's perspective its to the left)
this might be a order of operations problem, in your code you have this:
Code:
vsp += grv;
if (place_meeting(x,y+1,oWall) && place_meeting(x+1,y,oWall) || place_meeting(x-1,y,oWall)) {
    vsp = -5;
}
the if statement is checking first if you are on the wall and to the right wall, or if you are on the left wall, you want it to say if you are the ground and either on the left or right wall.
Sorry if that was confusing just add periphrases like so and you should be fine
Code:
vsp += grv;
if (place_meeting(x,y+1,oWall) && (place_meeting(x+1,y,oWall) || place_meeting(x-1,y,oWall))) {
    vsp = -5;
}
Hope this helped! :confused:
-CloseRange
 
R

robeng

Guest
For future refrence it would be proper to say they are climbing the left wall (becuase in the enemy's perspective its to the left)
this might be a order of operations problem, in your code you have this:
Code:
vsp += grv;
if (place_meeting(x,y+1,oWall) && place_meeting(x+1,y,oWall) || place_meeting(x-1,y,oWall)) {
    vsp = -5;
}
the if statement is checking first if you are on the wall and to the right wall, or if you are on the left wall, you want it to say if you are the ground and either on the left or right wall.
Sorry if that was confusing just add periphrases like so and you should be fine
Code:
vsp += grv;
if (place_meeting(x,y+1,oWall) && (place_meeting(x+1,y,oWall) || place_meeting(x-1,y,oWall))) {
    vsp = -5;
}
Hope this helped! :confused:
-CloseRange
Thanks! That fixed my issue!
 
Top