G
Oops. I also added the wall, its parent, and the player create event image.Do you have any collision code for us so we can help you?
//Get Player input
key_left = keyboard_check(vk_left); keyboard_check(ord("A"));
key_right = keyboard_check(vk_right); keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(vk_space);
// Calculate Movement
var move = key_right - key_left
hsp = move * walksp;
vsp = vsp + grv;
if (place_meeting(x,y+1,obj_wall_parent)) && (key_jump)
{
vsp = -7;
}
// Horizantail Movement
if (place_meeting(x+hsp,y,obj_wall_parent))
{
while (!place_meeting(sign(hsp),y,obj_wall_parent))
{
x = x = sign(hsp);
}
hsp = 0;
}
x = x + hsp;
// Vertical Movement
if (place_meeting(x,y+vsp,obj_wall_parent))
{
while (!place_meeting(x,y+sign(vsp),obj_wall_parent))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
//Doulbe Jump
ysp += grv;
if(keyboard_check_pressed(vk_space) && jump_current > 0)
{
ysp = -8
jump_current--;
}
if(place_meeting(x, y + ysp,obj_wall_parent))
{
while(!place_meeting(x, y + sign(ysp),obj_wall_parent))
{
y+= sign(ysp);
}
if(ysp > 0)
{
jump_current = jump_number;
}
ysp = 0;
}
y+= ysp;
Figured so, your code is pretty messy and the code order is not so optimal.Oops. I also added the wall, its parent, and the player create event image.
//Get Player input
key_left = keyboard_check(vk_left) || keyboard_check(ord("A"));
key_right = keyboard_check(vk_right) || keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(vk_space);
// Calculate Movement
move = key_right - key_left;
// motion
hsp = move * walksp;
// gravity
vsp += grv;
// reset jump counter on ground
on_ground = place_meeting(x,y+1,obj_wall_parent);
if (on_ground)
{
jump_current = jump_number;
}
// jumping
if (key_jump)
{
if (on_ground)
{
// basic jump
vsp = -7;
}
else
if (jump_current > 0)
{
// double jump
vsp = -8;
jump_current--;
}
}
// horizontal collision
if (place_meeting(x+hsp,y,obj_wall_parent))
{
while (!place_meeting(sign(hsp),y,obj_wall_parent))
{
x += sign(hsp);
}
hsp = 0;
}
x += hsp;
// vertical collision
if (place_meeting(x,y+vsp,obj_wall_parent))
{
while (!place_meeting(x,y+sign(vsp),obj_wall_parent))
{
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
x = x = sign(hsp);
x = x = sign(hsp);
x = x + sign(hsp);
Yeh, lol I didn't even notice. But yes, never combine variables, always use one that does everything, like hsp doing all horizontal motion and vsp all vertical motion.I replaced mine with your code, but now I can't jump at all.
Also, I think the
is supposed to beCode:x = x = sign(hsp);
right? I made that change too.Code:x = x + sign(hsp);
I'm combining different tutorials here, so that's why there is both vsp and ysp in the create event. Is it a bad idea to use both in one script?
Either way, I can't jump now. Thanks for your help with rearranging the code and using better variables.