Legacy GM Collision not working.

D

Dropsuitcaptain

Guest
My horizontal collision isn't working properly but my vertical is, could someone help please:p

my horizontal code:
Code:
if place_meeting(x+hspd,y,oHouse1){
    while !place_meeting(x+sign(hspd),y,oHouse1){
        x += sign(hspd);
    }
    hspd = 0;
}
my vertical code:
Code:
if place_meeting(x,y+vspd,oHouse1){
    while !place_meeting(x,y+sign(vspd),oHouse1){
        y += sign(vspd);
    }
    vspd = 0;
}
hspd is my variable for moving left & right.
I've also tried this on different objects and it gives me the same result.
Doesn't stop me like it's supposed to.
Any help is appreciated!
 

TheouAegis

Member
Are you using hspd or did you accidentally type hsp or hspeed? Don't just tell me what you use, go back and verify what you actually used throughout your entire code.
 

chamaeleon

Member
Checked and there's nothing but hspd.
Check the collision mask and bounding box variables to ensure your place_meeting() tests actually fire when they're supposed to given x and y? More fundamentally, figure out what aspect of your nested if statements for modifying x is not triggering, and debug it using the available tools (debugger, show_debug_message(), draw_text() in the draw event, etc.)
 
D

Dropsuitcaptain

Guest
Check the collision mask and bounding box variables to ensure your place_meeting() tests actually fire when they're supposed to given x and y? More fundamentally, figure out what aspect of your nested if statements for modifying x is not triggering, and debug it using the available tools (debugger, show_debug_message(), draw_text() in the draw event, etc.)
I tested this on a different project with centered collisions on the player and the wall (both 32x32 squares) and it still makes me pass right through the wall.
 
Can you show us your entire movement code? It may be something outside of your collision code that is making it so you can move horizontally onto the object.
 
D

Dropsuitcaptain

Guest
Can you show us your entire movement code? It may be something outside of your collision code that is making it so you can move horizontally onto the object.
step event:
Code:
//move
if keyboard_check(ord("D")){
    hspd = 3;
}else if keyboard_check(ord("A")){
    hspd = -3;
}
else{
    hspd = 0;
}

x += hspd;
y += vspd;


if !place_meeting(x,y+1,oWall){
    vspd += grav;
}else{
if keyboard_check_pressed(vk_space){
    vspd = -11;
}
}
//horizontal collision
if place_meeting(x+hspd,y,oWall){
    while !place_meeting(x+sign(hspd),y,oWall){
        x += sign(hspd);
    }
    hspd = 0;
}
//vertical collision
if place_meeting(x,y+vspd,oWall){
    while !place_meeting(x,y+sign(vspd),oWall){
        y += sign(vspd)
    }
    vspd = 0;
}
create event:
Code:
hspd = 0;
vspd = 0;
grav = 1;
 
Right after you check for the keyboard input, you are moving the player on the x and y, regardless of whether they are able to. That is your problem. You need to move the
Code:
x +=hspd;
y += yspd;
below all of your collision checks.
 
D

Dropsuitcaptain

Guest
Right after you check for the keyboard input, you are moving the player on the x and y, regardless of whether they are able to. That is your problem. You need to move the
Code:
x +=hspd;
y += yspd;
below all of your collision checks.
Ah I feel stupid now lol.
Thanks for your help!!:p:p:p
 
Top