How to make my code frame independent ?

Hello everyone… I have been working on my roller coaster physics for a few days, looking at assets and tutorials to get a functionning template to go from… The code I managed to write works great, it simulates sort-of realistic physics with mass friction and gravity… Unfortunately I do not know how to make it scale with the framerate… The math is consistent no matter the FPS but the coaster trains update slower as the frame rate lowers…

A few things to note: I’m using the Event Tick and I already tried using Timers and Async Physics tick with unsatisfying results, also, the math might not match any known formula and I don’t really mind it as long as it works.

My code is the following :

The float variable Increment is then used on tick to set the location at distance along spline. Current Distance + Increment = New Distance

Hopefully someone can help…

Solved:

Set gravity to -9800 (instead of -9.8), multiply by delta time, since gravity is in m/s

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.