M
Matthew Thibodeau
Guest
The movement in the game I'm working on appears to be bugged. It will not let me move right or left unless I've jumped first. If I start moving, I can keep moving, though sometimes changing the direction makes it stuck too. Jumping works good and as intended, its just sometimes the movement doesn't work as seamlessly as it should.
All my code was taking from Shaun Spaulding's tutorials, so I'm not sure what's wrong with it.
All sprites used in the object are set to Center, precise collision checking is turned off, and they are all the same size. I have no collision masks though I'm not sure if that's even related to this. This seems like something wrong with the movement coding.
Here is my Create Event:
///Initialize Variables
Here is my Step Event:
All my code was taking from Shaun Spaulding's tutorials, so I'm not sure what's wrong with it.
All sprites used in the object are set to Center, precise collision checking is turned off, and they are all the same size. I have no collision masks though I'm not sure if that's even related to this. This seems like something wrong with the movement coding.
Here is my Create Event:
///Initialize Variables
Code:
grav = 0.2;
hsp = 0;
vsp = 0;
jumpspeed = 7;
movespeed = 4;
image_speed = 0.25;
Here is my Step Event:
Code:
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_space);
//React to inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 10) vsp += grav;
if (place_meeting(x,y+1,obj_sand))
{
vsp = key_jump * -jumpspeed
}
//Horizontal Collision
if (place_meeting(x+hsp,y,obj_sand))
{
while(!place_meeting(x+sign(hsp),y,obj_sand))
{
x += sign(hsp);
}
hsp = 0;
}
x += hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,obj_sand))
{
while(!place_meeting(x,y+sign(vsp),obj_sand))
{
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
//Animate
if (move != 0) image_xscale = move;
if (place_meeting(x, y+1, obj_sand)) {
if (move!=0) sprite_index = sponge_run_right; else sprite_index = sponge_idle_right;
}
else
{
if (vsp < 0) sprite_index = sponge_jump_right; else sprite_index = sponge_fall_right;
}