• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Gravity with delta_time

R

RobotoSkunk

Guest
I was trying to add a system to make my game show no delay when playing and I started to have problems with gravity ... when multiplying the gravity by delta I started to see errors such as the player jumps very little when the game runs at 30FPS, but when the game increases to 60FPS it jumps higher ... can someone help me? ;-;

Delta code:
Code:
delta = 60/1000000*delta_time;
Step event:
Code:
col = collision_line(x, y, x, y+vspeed, obj_block, 0, 1) || place_meeting(x, y, obj_block) || place_meeting(x, y+vspeed, obj_block);
jump = keyboard_check(vk_space) || keyboard_check(vk_up) || mouse_check_button(vk_left) || gamepad_button_check(gamepad, gp_face1);

if(col){
    for(var i = 0; i < abs(vspeed); i++){
        if place_meeting(x, y, obj_block) then break;
        y += sign(vspeed);
    }
    if place_meeting(x, y, obj_block) vv = -jump_boost*jump;
} else {
    vv += grav*delta;
    vv = clamp(vv, -jump_boost, jump_boost);
}

hspeed = vh[1]*delta;
vspeed = vv;
EDIT: I also tried pulling out the delta square, but it gives me almost the same result :c
 

jo-thijs

Member
I was trying to add a system to make my game show no delay when playing and I started to have problems with gravity ... when multiplying the gravity by delta I started to see errors such as the player jumps very little when the game runs at 30FPS, but when the game increases to 60FPS it jumps higher ... can someone help me? ;-;

Delta code:
Code:
delta = 60/1000000*delta_time;
Step event:
Code:
col = collision_line(x, y, x, y+vspeed, obj_block, 0, 1) || place_meeting(x, y, obj_block) || place_meeting(x, y+vspeed, obj_block);
jump = keyboard_check(vk_space) || keyboard_check(vk_up) || mouse_check_button(vk_left) || gamepad_button_check(gamepad, gp_face1);

if(col){
    for(var i = 0; i < abs(vspeed); i++){
        if place_meeting(x, y, obj_block) then break;
        y += sign(vspeed);
    }
    if place_meeting(x, y, obj_block) vv = -jump_boost*jump;
} else {
    vv += grav*delta;
    vv = clamp(vv, -jump_boost, jump_boost);
}

hspeed = vh[1]*delta;
vspeed = vv;
EDIT: I also tried pulling out the delta square, but it gives me almost the same result :c
There's a lot for me to comment on, but the thing that's most relevant to your issue is this line:
Code:
vspeed = vv;
You forgot to apply delta time here:
Code:
vspeed = vv * delta;
 
Top