Advertisement

Make This Motion Fps-Independent?

Started by August 06, 2016 01:59 PM
18 comments, last by _WeirdCat_ 8 years, 6 months ago

Another approach:

Store the original position, and increment x based on delta time.


float timeNeeded = 3.0f;
float increment = deltaTime / timeNeeded;
x += increment;

x = clamp(x, 0.0f, 1.0f);

position = originalPosition + (distance * x);

This will need a bit more logic to deal with cases where timeNeeded is 0.

Your approach doesn't work. The effect is exactly the same I've been getting all along - i.e., speed changing based on the framerate, in fact it seems even worse than a couple of cases I was able to obtain.

The effect is exactly the same I've been getting all along - i.e., speed changing based on the framerate

Sorry, I must have misread your post.

But surely this is what you'd want in a game? Shouldn't traveling x distance always take the same amount of time, and not depend on whether your computer is awesome or not? With a varying frame rate, a varying distance moved per frame would have to be the case in order to compensate, in order to keep the total time equal.

It feels like I'm missing something -- care to explain?

Hello to all my stalkers.

Advertisement

The effect is exactly the same I've been getting all along - i.e., speed changing based on the framerate

Sorry, I must have misread your post.

But surely this is what you'd want in a game? Shouldn't traveling x distance always take the same amount of time, and not depend on whether your computer is awesome or not? With a varying frame rate, a varying distance moved per frame would have to be the case in order to compensate, in order to keep the total time equal.

It feels like I'm missing something -- care to explain?

Exactly! The way your approach (and my previous attempts) worked, the framerate did nothing to mitigate the wobbling of the movements. In other words, it would abnormally speed up when the framerate increased and slow down when it decreased. This should not happen.

I really don't see how that can be the result of what I posted. I'm quite confused now.

Hello to all my stalkers.

I don't know, but that's the result I got. Maybe I've implemented it wrong. Here's my function:


void Entity::updatePos(float delta)
{
    float3 distance = this.destination - this.position;

    float timeNeeded = 3.0f;
    float increment = delta / timeNeeded;
    this.X += increment;
    this.X = clamp(X, 0.0f, 1.0f);
    
    this.position += distance * this.X;

    ...
}

I know for a fact the `destination` is updated correctly, so no problem there.

Note that I wrote storing the original position (the entity's position when the destination was set).

Hello to all my stalkers.

Advertisement

Ah, I missed that. Well, as I said earlier I can't do that unfortunately. I can only interpolate the current position over the friction, the destination and the delta. This is because the destination is variable at any point in time.

In that case, I would go with Irlan's solution :)

Hello to all my stalkers.

Yeah, it seems like it's the most stable one out of the 326 I've tried. Thanks for the input though! Still very useful if one can do it that way. :)

to get even smoother movement use some high precision timer, or use average of times between two frames, as delta time.

This topic is closed to new replies.

Advertisement