Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [Code] Fixed Physics, free from Frame Rate

Author
Message
brunuu
5
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 21st Sep 2023 18:50 Edited at: 21st Sep 2023 18:51
It is a common problem that physics do not have the same behavior at different framerates.
I came here to share a solution that I also use, because it was a problem that took me a long time to solve.
and I'm sure there will be someone else with similar problems


In AppGameKit there are multiple solutions, however all of them will present some disadvantages, especially when there are hundreds of dynamic objects, or hundreds of joints
specifically when there are hundreds of joints, the physics tend to behave very poorly at framerates below 30fps, regardless of whether you use fixed step or not.
and there are other solutions that will add input delay

However, I think this solves all the problems relating to physics and framerate, whether at 10fps or 1000fps.

adambiser
AGK Developer
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 21st Sep 2023 22:23
Instead of calling Update like that, I call StepPhysics with a constant physics frame rate. When it's not a physics tick, I use StepPhysics(0) so that Sync doesn't call StepPhysics internally.
brunuu
5
Years of Service
User Offline
Joined: 4th Jun 2018
Location:
Posted: 22nd Sep 2023 01:36
Yes, I also used a similar method, which was even a script made by you

But recently I noticed some delays on the sprites when moving with other sprites position at the same time, with SetSpritePosition
And this delay was smaller depending on the frame rate

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 27th Oct 2023 19:48 Edited at: 27th Oct 2023 19:53
trying this out where i've always let a 30 fps sync rate handle it for my simple games and gotten away with it but shouldn't the last step/update be a fraction of a full RENDER_FRAME_TIME?

otherwise you're pushing a full RENDER_FRAME_TIME before it should (fully) trigger?

Login to post a reply

Server time is: 2024-04-27 19:06:43
Your offset time is: 2024-04-27 19:06:43