Public Group

# Laggy sfml Moving object, how to fix it ?

This topic is 1323 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi to all !
Month ago I start research smooth fixed constant moving.
http://gafferongames.com/game-physics/fix-your-timestep/

Then was begun some tests.
And problem is !!!

Again I see a little bit laggy if You see some more time on movObject.
What my wrong ?
Maybe some improved interpolation needs ?
Please specify how to fix and achieve smooth moving using constant velocity.

Here sources (MSVS) >> https://www.dropbox.com/s/nkkegjudjtoosly/Moving%20object%20c%2B%2B.zip?dl=1
-
Here main code to easy fast read > http://pastebin.com/he8TMHgi

##### Share on other sites

Not an expert on Gaffer's stuff, but the thing that sticks out to me, it looks like your then interpolating prevState and currState, but those will basically be nearly the same because of that assignment.

  accum += elTmeMicros;
while(accum >= tmeStep)
{
prevState = currState;  // <-- What's this?
currState.x += velX * tmeStep;
currState.y += velY * tmeStep;
accum -= tmeStep;
}

Edited by ferrous

##### Share on other sites
without looking at the code, did you remember that when rendering, you need to account for the remainder of accum % timestep? otherwise movement will be smooth under the hood,but will look jittery when rendered.

##### Share on other sites

Yes people - I fully understand interpolation.

My goal is to achieve smooth moving using constant velocity.

Using for this interpolation, extrapolation or some other simpler methods.

What you using for stable motion on different fps ?

Hope you can share your sources for understand.

Thank you !

##### Share on other sites
gaffer has this part like this:

const double alpha = accumulator / dt;
State state = currentState * alpha + previousState * ( 1.0 - alpha );

render( state );

it means that when rendering, you interpolate precisely between states on timesteps, not just render data from full timesteps.

##### Share on other sites

Nope Gaffer has prevState, currState and State (for interpolation). Here no deal !(

There no mistakes but I want more stable motion.

##### Share on other sites
actually i copied that from the article, so that is how he has it. and looking at your code that is how you have it too. it looks ok and it's a proper way of doing it. can you insert some prints in your code to show values of elTmeMicrosec and alpha per frame?

##### Share on other sites

Maybe you advice me your own method to moving objects and code also ???

Yo no understand basic things of C++ language ?? (use -- cout << variable << endl;)

For what we now talking then,  hmmmm.. ((

Its very difficult part of game development and no simple talking around this.

Otherwise need complete solution to fix motion.

My solution looks like sufficient but want more proper motion.

If you using somewhere Box2D you can see normal motion, but me need simple motion for simple constant velocity ONLY.

Thanks for responds!

Edited by Redee

##### Share on other sites
i also use the method from the last paragraph of gaffer's article. and i was not asking if you are able to program that, but asking you to actually do it to take a look at the timings. the reason i asked that is because the method should provide you with smooth movement - if it doesn't, there may be something off about the timings. also please don't get insulting, i am not trying to piss you off, i am trying to narrow down the area where the problem may come from. by just looking at a few dozen lines of per-frame-timings we may be able to spot what is causing the jitter you experience. besides the elapsedTime and alpha, also check if and how often the accum loop gets executed per frame.

##### Share on other sites

Sfml is famous framework - no wrong with drawing and display !!!

Gaffer method in my implementation also all good.

Ok no information for me.

I hoped for some new interpolation or other new method.

Thank you.

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633319
• Total Posts
3011340
• ### Who's Online (See full list)

There are no registered users currently online

×