GM:S 1.4 Gravity with delta_time

Discussion in 'Programming' started by RobotoSkunk, May 29, 2019.

  1. RobotoSkunk

    RobotoSkunk Member

    Joined:
    Dec 24, 2018
    Posts:
    41
    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
     
  2. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    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;
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice