B
Bomb The Moon
Guest
I am new to GMS. I have primarily been following Shaun Spalding's tutorials, as a platformer is the first project i wanted to tackle.
My issue is this:
when i walk off of my moving platforms, in certain spots close to the walls, my player object jumps (as in a quick movement, not my coded jump) into the wall and gets stuck.
The collision seems to be working well otherwise, and seems like it should be preventing this from happening.
This is the relevant bit of my player object's step event, where most everything is housed for now...
this is the step event from the moving platfrom...
(also a jump-through platform)
Any help would be greatly appreciated.
Thanks is advance!
edit: at first i though that my moving platform was pushing me through the wall, so i tried out some code that would kill the player if caught between the two objects, but it happens even when i am 2-3 times my player object's width away from walls, so that didn't work.
My issue is this:
when i walk off of my moving platforms, in certain spots close to the walls, my player object jumps (as in a quick movement, not my coded jump) into the wall and gets stuck.
The collision seems to be working well otherwise, and seems like it should be preventing this from happening.
This is the relevant bit of my player object's step event, where most everything is housed for now...
Code:
var hspd_final = hspd + hspd_carry;
hspd_carry = 0;
//collision
//horizontal collision
var hcollide;
hcollide = instance_place(x+hspd_final, y, par_wall)
if (hcollide != noone)
{
if((hcollide).type ==1)
{
if (place_meeting(x+hspd_final, y, par_wall))
{
while (!place_meeting(x+sign(hspd_final), y, par_wall))
{
x =+ sign(hspd_final)
}
hspd_final = 0;
hspd = 0;
}
}
}
x += hspd_final;
//vertical collision
var vcollide;
vcollide = instance_place(x, y+vspd, par_wall);
if (vcollide != noone)
{
if ((vcollide).type == 1)
{
while (!place_meeting(x, y+sign(vspd), par_wall))
{
y += sign(vspd);
}
vspd =0;
grounded =1;
}
if (((vcollide).type ==2) && sign(vspd) == 1)
{
if (!place_meeting(x, y, par_wall))
{
while (!place_meeting(x, y+sign(vspd), par_wall))
{
y += 1;
}
vspd = 0;
grounded = 1;
}
}
}
else
{
grounded = 0;
}
y += vspd;
//jumping
if (grounded)
{
jumps = jumpsmax;
}
if ((key_jump) && (jumps > 0))
{
vspd = -jumpspd;
jumps -= 1;
}
//ladder
if (key_up || key_down)
{
if (place_meeting(x,y,par_ladder))
{
ladder = true;
}
}
if (ladder)
{
vspd = 0;
grav = 0;
//hspd=0;
if (key_up) vspd =-2;
if (key_down) vspd = 2;
if !place_meeting(x,y,par_ladder) ladder = false;
if (key_jump) ladder = false;
}
else grav = 0.2;
(also a jump-through platform)
Code:
hspd = dir * movespd
if (place_meeting(x+hspd, y, par_wall))
{
while(!place_meeting(x+sign(hspd), y, par_wall))
{
x += sign(hspd); //move one pixel until collision
}
hspd = 0; //colliding, stop moving
dir *= -1;
}
x += hspd;
if (instance_exists(obj_player))
{
if (place_meeting(x, y-1, obj_player))
{
obj_player.hspd_carry = hspd;
}
}
Thanks is advance!
edit: at first i though that my moving platform was pushing me through the wall, so i tried out some code that would kill the player if caught between the two objects, but it happens even when i am 2-3 times my player object's width away from walls, so that didn't work.
Last edited by a moderator: