Sphere, Friction and variable time steps [SOLVED]

Started by
4 comments, last by Endurion 18 years, 11 months ago
Hi, i'm working on a Marble Madness type game and got a dumbed down physics system working pretty well. What i'm having trouble with are varying frame rates. In fullscreen i'm vsynced to 100 Hz, in windowed mode i may get up to 350 Hz. This leads to some problems as the ball is not able to get up slopes in windowed mode will it's no problem in fullscreen. I'm aware that my "physics" are far from being correct, so i need a few hints. Right now i'm having a force vector (coming from mouse movement aka user input). Onto this vector i'm adding a slope vector multiplied by the grounds friction factor (to make the ball roll down a slope). Now in the balls update function i'm applying the force onto the balls speed vector. And that's probably where the problem lies: vectSpeed = vectSpeed * ( 1.0f - fElapsedTime ) + vectForce * fElapsedTime; This approximation seems close but as told above, it has it's turndowns. What would be the correct way to lerp the speed vector into the force vector with a variable time step value? Thanks in advance! [Edited by - Endurion on May 26, 2005 9:42:08 AM]

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Advertisement
This isn't really an answer to your question, but you probably should use constant time steps, then either limit your frame rate to that or use some kind of simple interpolation to render intermediate frames. Constant framerate makes your simulation a lot more predictable and you can easily make a playback feature that can be useful for debugging.
Fix your timestep!

Gaffer's article
Well, looks like i gotta cap the framerate. I hoped to come by without. Oh well.

Thanks though, interesting link as well.

What nobody ever tells, there has to be a solution formula wise actually? I see there'll probably be lots of precision and rounding errors making different frame rates still behave differently although the formula would be correct.

Rating++ for you!

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

1337 - what a wonderful rating you have ;)

you don't need to fix your graphics framerate... only the physical one... just in case that wasn't clear :)
Arghhhhh, i need to shoot myself.

After changing the physics to timestepped it still didn't work out. After further investigation i found that i applied the elapsed time onto the mouse movement before setting it to the object force. Grand. Meaning higher frames would lessen the users "power".

Things work fine now! Thanks again!

Squirm (Leonard?): Two days ago i had both rating and post count on 1337. But i couldn't post a brag thread in the lounge, it would've changed it :)

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

This topic is closed to new replies.

Advertisement