Skip to content

self.player.dy and self.y depend on FPS (dt) #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
LZNEWT00Z opened this issue May 5, 2021 · 0 comments
Open

self.player.dy and self.y depend on FPS (dt) #4

LZNEWT00Z opened this issue May 5, 2021 · 0 comments

Comments

@LZNEWT00Z
Copy link

LZNEWT00Z commented May 5, 2021

Example in Bird.lua 23:32

function Bird:update(dt)

    self.dy = self.dy + GRAVITY * dt
    if love.keyboard.wasPressed('space') then
        self.dy = -5
        sounds['jump']:play()
    end

    self.y = self.y + self.dy
end

Each dt self.y increases. Particularly if FPS is 60 then after 2 seconds (120 frames) self.y == (VIRTUAL_HEIGHT / 2 - 8) + 2420. In case of having 144 FPS after 2 seconds (288 frames) self.y == (VIRTUAL_HEIGHT / 2 - 8) + 5780.

I opened a pull request #5 fixing the issue in Bird.lua. Will add another one (if there's none) for the mario project once I finish the module.


FYI, here's the formula of the original self.y: (VIRTUAL_HEIGHT / 2 - 8) + (GRAVITY / FRAME_RATE) * (FRAMES * (FRAMES - 1) / 2). I made it like this: (VIRTUAL_HEIGHT / 2 - 8) + (GRAVITY * 60/ FRAME_RATE^2) * (FRAMES * (FRAMES - 1) / 2). This way self.y should change the same over the same period of time with different frame rates. I also multiplied the "anti-gravity" burst by 60 (the original frame rate). I tested it with different refresh rates (30, 60, 144, 155) and it seems to work the same now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant