how to achieve perfect framerate independence ?

0 favourites
  • 13 posts
From the Asset Store
Particles support animations, collisions, effects and etc.
  • Hi! I made this simple example, to explain the problem. The physics sprite(black) falls down, and when it reaches the yellow sprite.Y, a distance joint creates. And then the joint removes when it reaches the yellow sprite.Y again. The problem is, that in different fps, the jump height is different. Although timings are quite similar, and even the speed of falling is almost the same. and the lower the fps, the lower it jumps. Stepping mode is set to "framerate independent" but it doesn't help. how can I achieve at least approximately the same result at different fps? (the texts below and above on video, show the time when the joint is created, and when it reaches its highest point)

    Or, how can I set the maximum framerate for my game to 60 for example?

    I am grateful in advance for your help.

  • With a varying time step what the y is when you add or remove the joint will vary, which is why the height differs.

    One way to have it repeatable is to use a fixed time step so the y position will be consistent. Of course the sim will run twice as fast at 120fps.

    I’m don’t think there’s much you can do with the builtin physics behavior to make it more repeatable.

    If you did the physics manually you’d have more control. Such as updating at a fixed rate and lerping in between steps. Or calculating the exact time to add the joint and use equations for the exact motion of a kinematic body and a pendulum.

  • after many experiments, I found that the movement of a physical objects can be framerate independent. But rotation, such as joints, or angular velocity, or even torque depends on fps and give different velocity. The difference in simulations in different fps appears only after any rotation via physics engine. I do not know how to make physics manually, but it seems my whole project went down the drain (

  • The physics behavior is not great for precision or deterministic/repeatable motion. It's either framerate independent and not perfectly consistent, or framerate dependent but more consistent.

    There are always manual ways to simulate physics with math though. After all, the physics behavior is a simulation itself. Depending on the scope of what you're trying to do, the solution could be actually much simpler than a full physics environment simulation.

  • Of course, I understand that mathematics is more reliable, but I've been animating 3d characters for the last 15 years, and I'm not good at it. It's a pity that the built-in physics does not allow you to do anything serious. I found this solution.

    I'll try to figure it out.

    Thank you for trying to help.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Here's a simple test of event based physics that will update at the same rate regardless of the screen refresh rate. So motion of objects will be consistent.

    The physics is done with verlet integration, and uses a small step so it's more accurate and loses less energy over time. The position is interpolated between simulation steps to give smooth motion with different fps. I followed your example video and made it connect with a distance joint when below a certain point, and then remove the joint when above.

    Anyways, the physics is pretty bare bones. Objects falling with gravity with optional joints to the layout per object. More deluxe physics can be made depending on what's needed.

    For something simple like this we can go a step further by finding equations of motion so we get the exact path without energy loss, but that may be a bit of a overkill.

  • Here's a simple test of event based physics that will update at the same rate regardless of the screen refresh rate. So motion of objects will be consistent.

    thank you so much for wasting your time. It looks amazing. It will take me some time to figure out all this logic, but I managed to make some changes to get the desired result. For example, I can add an impulse by adding a value to vx and vy. I can stop and restore sprite by adding time to pTime. Figured out how to add gravity. But I can't figure out how to make the sprite heavier . Is it possible?

  • It’s no waste of time. It’s something I’m interested in and it was fun to try it.

    The gravity is handled by the “add 400*mdt” action. You can change the 400 to adjust the strength of it.

    I didn’t include mass, which would allow you to make things heavier. But that would only change things if you applied a force, impulse or deal with collisions or a joint between objects. As is, the joint with the layout and gravity would be the same regardless of how heavy the objects are.

    Anyways, if you wanted to apply an impulse and take mass into consideration you’d do:

    Add impulseX/mass to vx

    Add impulseY/mass to vy

    It’s best to not touch pTime. That would just advance the simulation forward in time more. It wouldn’t conserve energy.

  • It’s best to not touch pTime. That would just advance the simulation forward in time more. It wouldn’t conserve energy.

    look at this please.

    what if I stop and restore the time in this way? it works for me as it should. the movement continues at the same speed as it was before the stop. I can even set the vx and vy values to start moving at the desired speed.

    I need the heaviness so that it jumps not so high, and for more dumping. When I change the gravity, it just move faster or slower, but the amplitude remains the same. I can't figure it out without your help.)

  • Ah, I see what you mean. You want damping. Re-download from my post.

    There are two ways you can introduce damping. One is to change damping from 1 to say 0.995. Another is to make the timestep bigger, so change step from 0.0005 to 0.005 or something. I had used a small step initially so that the balls would end up about the same height.

  • One last question, and I'll leave you alone.)) Unfortunately, it looks like the dumping variable is not used anywhere in the event sheet. where do I need to enter it?

    special thanks for the group activation button!)

  • Oops. I’ll need to fix that and reupload. You’d add it to the velocity update event.

    Set vx to (self.x-self.px)/step*damping

    Set vy to (*damping

    Let me know if there are any other features needed.

  • R0J0hound So far, this is quite enough for my purposes. I am very grateful to you. you've helped me a lot.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)