I made a little game with side-scrolling and a box (the player) jumping across the level. The simple physics are almost done, but I have two problem with the way things behave:
- On landing, the box takes a little time to reach the floor
- When the box hit a roof, there is always a little space between it and the object.
Here is my collision code (in the player's Step Event):
myGravity = 0.5;
if (vspeed > 10) vspeed = 10;
speedAir = abs(vspeed+1);
//ON_FLOOR = !(place_free(x, y + speedAir));
ON_AIR = place_free(x, y + speedAir);
FREE_RIGHT = place_free(x + speedScreen, y);
FREE_UP = place_free(x, y - speedAir);
KEY_UP = keyboard_check(vk_up);
KEY_LEFT = keyboard_check(vk_left);
KEY_RIGHT = keyboard_check(vk_right);
KEY_FIRE = keyboard_check(vk_space);
/* JUMP */
if ON_AIR
{
gravity = myGravity;
gravity_direction = 270;
if !(FREE_UP)
{
vspeed = 0;
}
}
else // if ON_FLOOR
{
gravity = 0;
gravity_direction = 270;
vspeed = 0;
// JUMP
if KEY_UP & FREE_UP
{
vspeed = -10;
}
}
/* LATERAL */
if (FREE_RIGHT)
{
x += speedScreen; // screen side-scrolling
}
How can I do this correctly?