I've looked everywhere, KHMovement, FPS guides, the manual, these forums and I can't find a solution to my jumping problem. The code works, just not smoothly. I want a nice steady arc upward and downward at the same speed like the old Mario games jumping. The code below works it's just sometimes the player will hang in the air and "fly" before they come back down. Can anyone help me out and tell me what I'm doing wrong?
action players_vehicle
{
player = me;
my.falling = 0;
my.shadow = on;
while (lives > 0)
{
vec_set(temp,my.x);
temp.z -= 1000;
my.fall_distance = c_trace(my.x, temp, IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES|ACTIVATE_SONAR|SCAN_TEXTURE|USE_BOX);
//check if jumping
if (my.jumping != 0)
{
if (my.jump_height > 256 && my.jumping == 1)
{
my.jumping = 0;
move_vec.z = 0;
my.jump_height = 0;
}
else
{
if (move_vec.z > 1*time)
{
move_vec.z -= .3*time;
my.jump_height += move_vec.z;
}
else
{
move_vec.z = 1*time;
my.jump_height += move_vec.z;
}
}
}
//check if falling
if (my.fall_distance > 500 && sign(my.fall_distance) != -1 && my.jumping == 0)
{
my.falling = 1;
}
else
{
if (my.fall_distance < 500 && my.falling == 0 && my.jumping == 0)
{
move_vec.z = -my.fall_distance*time;
}
}
if (my.fall_distance > 256)
{
my.falling = 1;
if (move_vec.z > -20*time)
{
move_vec.z -= .3*time;
}
}
if (key_j)
{
if (my.jumping == 0 && my.falling == 0 && my.fall_distance < 1)
{
my.jumping = 1;
move_vec.z = 45 * time;
}
}
move_vec[0] = (key_cur + key_cul)*25 *time;
if (key_cur == 1){my.pan = 0;}
if (key_cul == 1){my.pan = 180;}
c_move(me,move_vec,nullvector,IGNORE_PASSABLE|GLIDE);
player_animate();
handle_camera();
wait(1);
}
}
function player_animate()
{
my.skill1 += 3*time_step;
if (my.skill1 > 100) {my.skill1 -= 100;}
if (my.falling == 1)
{
if (my.fall_distance < 0)
{
move_vec.z = -my.fall_distance*time;
}
else
{
my.falling = 0;
}
}
if (move_vec[0] == 0 && move_vec[1] == 0)
{
ent_animate(me,"idle",my.skill1,ANM_CYCLE);
}
else
{
ent_animate(me,"roll",my.skill1,ANM_CYCLE);
}
}
function handle_camera()
{
camera.x = my.x;
camera.y = my.y - 1500;
camera.z = my.z + 100;
camera.pan = 90;
}