H
Half
Guest
This is a code that I got from a youtube video (the step event of obj_player, which is the controllable character):
I have a controllable character that can jump around and land on platforms, but when it touches the side of a platform the character freezes in the air and the game crashes.
Is there something that is missing from the code?
Code:
/// platform physics
// Check for ground
if (place_meeting(x, y+1, obj_solid)) {
vspd = 0;
//Jumping
if (keyboard_check(vk_up)) {
vspd = -jspd
}
} else {
//gravity
if (vspd < 10) {
vspd += grav;
}
}
// Moving right
if (keyboard_check(vk_right)) {
hspd = spd;
}
// Moving left
if (keyboard_check(vk_left)) {
hspd = -spd;
}
// Check for not moving
if ((!keyboard_check(vk_right)) && !keyboard_check(vk_left) || !keyboard_check(vk_right) && !keyboard_check(vk_left)) {
hspd = 0;
}
// Horizontal collisions
if (place_meeting(x+hspd, y, obj_solid)) {
while (!place_meeting(x+sign(hspd), y, obj_solid)) {
x+= sign (hspd);
}
hspd = 0;
}
//Move horizontally
x += hspd;
// Vertical collisions
if (place_meeting(x+hspd, y+vspd, obj_solid)) {
while (!place_meeting(x, y+sign(vspd), obj_solid)) {
y+= sign (vspd);
}
vspd = 0;
}
//Move vertically
y += vspd;
Is there something that is missing from the code?