Provide that newton always runs the same speed

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Provide that newton always runs the same speed

Postby FSA » Mon Dec 17, 2012 9:04 am

Hi. I have a problem with the speed by different framerates. I call NewtonUpdate with the time since last frame. But my player doesn't move always the same speed(I set the velocity to 30.0f). The strange thing is, all other objects move with the same speed. They doesn't go slowly they just jerky but the player move in slow motion.
Thank you.
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Provide that newton always runs the same speed

Postby Sweenie » Mon Dec 17, 2012 9:31 am

Usually it's better to run the simulation with a fixed timestep.
Due to the linear damping on the object not being affected by elapsed time objects tend to slow down faster if the frame rate is high.
Does your player object have a different linear damping than the other objects?
Sweenie
 
Posts: 503
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Provide that newton always runs the same speed

Postby JoeJ » Mon Dec 17, 2012 9:40 am

You must run newton with fixed timesteps.
Something like:

//init:
float newtonTime = System.Time();

//runtime:
float realtime = System.Time();
while (newtonTime < realtime)
{
float timestep = 1/60;
newton.StepWorld(timestep);
newtonTime += timestep;
}

Now newton runs smooth, but your graphics may look a bit choppy.
To fix that, you'd need to remember the last state for each body, and interpolate it with the current state depending on real time.
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Provide that newton always runs the same speed

Postby FSA » Mon Dec 17, 2012 9:59 am

No I have no other damping values.
@JoeJ: I habe try it. Now I have some errors on claculating torque. And also the player is slower by smaller framerate.
Other ideas?
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Provide that newton always runs the same speed

Postby FSA » Mon Dec 17, 2012 10:42 am

@JoeJ: How can I interpolate when i just have one frame to update the positions?
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Provide that newton always runs the same speed

Postby JoeJ » Mon Dec 17, 2012 11:10 am

letter123 wrote:I habe try it. Now I have some errors on claculating torque. And also the player is slower by smaller framerate.

There must be something wrong. I've had problems like "This requires milliseconds but the other thing gives nanoseconds" - my solution is too messy to show, but you can look at the newton demo sandbox.

How can I interpolate when i just have one frame to update the positions?

You need to store the state (position + orientation) for each body after each timestep,
so, after the step you have the results from the previous step and the actual state.
Similar you store the time mark from the previous step and the current step, then it's easy:

float t = (realTime - oldNewtonTime) / (currentNewtonTime - oldNewtonTime);

gfxPos = body.oldPos * t + NewtonBodyGetPos(body) * (1 - t);
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Provide that newton always runs the same speed

Postby FSA » Mon Dec 17, 2012 11:24 am

I'll give it a try. Thank you!
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Provide that newton always runs the same speed

Postby JoeJ » Mon Dec 17, 2012 2:08 pm

... maybe it's good enough to use angular and linear velocity to approximate state at a point in time.
I guess it won't be visible :)
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest