# Framerate based smoothing

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

## Recommended Posts

So, I have another problem: I want my Camera to move and rotate smoothly, but I just can't figure out how to do this FPS based. what I mean is: When you have a player, and you add 1 to hims location every frame, he will be too fast with many FPS, and too slow with low FPS. To fix this, you can easily do Speed/FPS, but what can I do when I want it smooth? Here is what I'm currently doing:
void Camera::Tick()
{
bool bDoneSomething=false;
if(SmoothLocation!=D3DXVECTOR3(0,0,0))
{
Location+=SmoothLocation;
SmoothLocation*=SmoothSpeed;
bDoneSomething=true;
}

if(SmoothRotation!=D3DXVECTOR3(0,0,0))
{
Rotation+=SmoothRotation;
SmoothRotation*=SmoothSpeed;
bDoneSomething=true;
}

...


SmoothSpeed is a float at 0.5. Can you help me with this?

##### Share on other sites
I covered this in my most recent tutorial - you should be able to extract the relevant code fairly easily.

##### Share on other sites
Yes, thats a nice tutorial, but where is the stuff about smooth moving objects? Or did I just missed it?

##### Share on other sites
Quote:
 Original post by mind in a boxYes, thats a nice tutorial, but where is the stuff about smooth moving objects? Or did I just missed it?
The coded uses a timer class that averages the last few frames to smooth out spikes, and then uses that smoothed time to move objects based on a speed in units / sec and the time elapsed that frame.
The actual object update is done in D3DWindow::UpdateLogic() and Sprite::Tick().

##### Share on other sites
This is very useful, and I'm building it in at the moment, but not exactly that what I wanted. Just imagine you control a spaceship. When you touch one of your move-keys, it will move. What else, its a move key :P. But when you release it, the ship will need some time to stand still. Your Tutorial seem to be only about smoothing the FPS, and not about FPS based smoothing...

##### Share on other sites
Quote:
 Original post by mind in a boxThis is very useful, and I'm building it in at the moment, but not exactly that what I wanted. Just imagine you control a spaceship. When you touch one of your move-keys, it will move. What else, its a move key :P. But when you release it, the ship will need some time to stand still. Your Tutorial seem to be only about smoothing the FPS, and not about FPS based smoothing...

You aren't describing FPS-based smoothing, though, you're describing inertia. For that you want to look into things like springs, damping and friction :)

##### Share on other sites
Yes, maybe. I don't know. When you multiply a value every frame with 0.9 it will go to 0 smoothly. Thats what I want to do, but with implying the FPS.

I just want that my Camera has a smooth rotation...

##### Share on other sites
Like:

Position += Velocity * deltaTime;
Velocity *= 0.9f * deltaTime;

Where deltaTime is the amount of time between this point and the last frame.