Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6972379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:57:37+00:00 2026-05-27T16:57:37+00:00

I’m trying to copy the logic of the Sonic physics engine , which was

  • 0

I’m trying to copy the logic of the Sonic physics engine, which was written for a fixed-timestep system (60 FPS), in a variable timestep age (Slick2D, to be precise).

In the original upon pressing the jump button, the player’s velocity.y is set to -6.5, and each tick 0.21875 is added to velocity.y to model gravity.

Each time my logic update is called, a time delta parameter is passed specifying how many millis have passed. If more millis have passed than I was expecting, then I repeat the update logic, passing an ‘inner delta’ that is at most 1, or less if we’re dealing with the ‘remainder’ of a target frame.

E.g. if we expect a frame to take 16ms, and it does take 16 ms, the loop will iterate once and pass thisMiniTick as 1. If the delta was not 16ms but 40ms, the loop will execute three times, passing 1, 1, and finally 0.5.

I mistakenly thought that in each of these inner update loops I could do velocity.y += (gravity * thisMiniTickRelative), but this doesn’t work. On faster framerates not enough gravity is applied causing a higher jump, and on slower framerates the jump is lower (although not anywhere near as noticeably).

Is there a way of doing this that will work for virtually all framerates, or must I resort to setting an upper and lower bound for delta?

The ‘inner update’ loop:

    float timeRemaining = delta/1000f; 
    while(timeRemaining > 0)
    {
        float thisMiniTick = Math.min(timeRemaining, 1f / FRAMES_PER_SECOND);
        float thisMiniTickRelative = thisMiniTick / (1f / FRAMES_PER_SECOND);

        updateInput(container, game, thisMiniTickRelative);
        if (playerAirState)
        {
            playerVelocity.y += (GRAVITY * thisMiniTickRelative);
        }
        clampPlayerVelocity();
        playerPosition.add(playerVelocity);
        doCollisions();
        timeRemaining -= thisMiniTick;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:57:38+00:00Added an answer on May 27, 2026 at 4:57 pm

    Don’t think of it as “resorting to setting an upper and lower bound for delta“. Your application and threads are subject to the OS scheduling time for your app, among all the other demands on the system, and something you just need to be aware of. This challenge is as old in PC gaming as the day we moved from single-tasking operating systems to multi-tasking operating systems.

    With Slick, you can (and should) disconnect your logic updates from your rendering updates, which is why the delta value gets passed around your application. Do this by using the .setMinimumLogicUpdateInterval and .setMaximumUpdateInterval methods.

    On projects that I’ve worked on, including one in Slick, I find that anything in the 30-60 logic updates per second (30.3 milliseconds to 16.6 milliseconds between updates) works great, and gives you the smoothness you need from your movement, physics, and collision calculations.

    Literally what that means is, for a 30-60 logic updates per second range, you want to do the following:

    container.setMinimumLogicUpdateInterval(16);  // max 60 logic updates per second
    container.setMaximumLogicUpdateInterval(31);  // min 30 logic updates per second
    

    Also, it’s a common mistake to try to calculate the timeRemaing value, but you don’t want to do this. You simply want to multiply how much you move, by how much time has passed. If 30 milliseconds have passed, that’s about 1/33rd of a second, so you should move your game object by 1/33rd of the amount it would move in 1 second.

    float timeElapsed = delta/1000f;
    
    playerVelocity.y += (GRAVITY * timeElapsed);
    

    With the upper/lower bounds set as specified above, you’re sure that timeElapsed will always be a value between 0.03 and 0.06. If your game gets bogged down and your frame rate slows down, your logic updates still won’t go outside these bounds. What will happen instead is the whole game will appear to slow down (as it should, just like on the old Sega days when there was too much on the screen), but collisions and physics calculations will still work as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.