GameMaker [SOLVED] Problem with collision

B

b38b38b

Guest
I am currently working on a 2D Plattformer, but I have a very big problem:
the player cant jump when he is touching a wall, but when hes only touching the floor everything is fine.
The wall and the floor are the same object.
Here is my code for collision and movement:
Code:
if (hascontrol) {

key_grenade = keyboard_check_pressed(ord("G"));
key_left = keyboard_check(ord("A"));
key_right = keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(vk_space);
key_down = keyboard_check(ord("S"));
key_up = keyboard_check(ord("W"));
}

else{

key_right = 0;
key_left = 0;
key_jump = 0;
key_down = 0;

}


//Calculate Movement
var move = key_right - key_left;

hsp = move * walksp;

vsp = vsp + grv;

if (place_meeting(x,y+1,oIwall))
{
   jumps = jumpsmax;
  
}
if (key_jump) && (jumps > 0) {

jumps -= 1;
vsp = -7.5;

}

//Moving Plattforms
var hsp_final = hsp + hsp_carry;
hsp_carry = 0;
var vsp_final = vsp + vsp_carry;
vsp_carry = 0;


//Horizontal collision
if (place_meeting(x+hsp_final,y,oIwall))
{
    while (!place_meeting(x+sign(hsp_final),y,oIwall))
 {
     x = x + sign(hsp_final);
 }
 hsp_final = 0;
    hsp = 0;
}

x = x + hsp_final;

//Vertical Collision
if (place_meeting(x,y+vsp_final,oIwall))
{
    while (!place_meeting(x,y+sign(vsp_final),oIwall))
 {
     y = y + sign(vsp_final);
 }
 vsp_final = 0;
 vsp = 0;
}
if (place_meeting(x+hsp_final,y,oIwall))
{
    while (!place_meeting(x+sign(hsp_final),y,oIwall))
 {
     x = x + sign(hsp_final);
 }
 hsp = 0;
 hsp_final = 0;
}
y = y + vsp_final;

I cant find a fix and I hope you can help me out !
 
B

Bayesian

Guest
I'm not seeing anything wrong with the code you posted, other than you have horizontal collision check repeated in the vertical section however that code isn't doing anything in that position.

The problem must be somewhere else in the code or your level design
 
B

b38b38b

Guest
I'm not seeing anything wrong with the code you posted, other than you have horizontal collision check repeated in the vertical section however that code isn't doing anything in that position.

The problem must be somewhere else in the code or your level design
Thanks for the tip.
I found the problem, the animation sprites had a wrong collsionmask.
 
Top