Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm making a camera which tracks the player. I am using a basic algorithm to calculate a position for the camera relative to the player. Then I am taking an average of this over the last x number of frames. This creates a nice chase camera which always slightly lags and evens out the players movements.

Where I am running into trouble is with delta Time. How can I weight each entry in my list of previous positions so that delta time is taken into account. Currently I'm having an issue where, when the frame rate is particularly slow, the camera lags really far behind the player.

I should also mention that currently I am adding each entry ElapsedTimeInSeconds/0.01f times to give the weight. So the average is effectively over fewer frames if the frame rate is slow. I also tried entering values as Value * DeltaTime, then keeping an average of delta time to divide the values by when I get them back out of my average tracking class but that didn't work.

What I think I really want is an average over the last n seconds rather than the last n frames.

share|improve this question
    
Not a direct answer, but have you considered using spring physics to model your chase camera? Here's an implementation in XNA taken from this sample. –  David Gouveia Apr 27 '12 at 2:38
    
The camera averaging is working really well as it is, I just want to fix issues caused by the frame-rate dropping. It gives me a lot of the desired effects like lagging more behind the player when their moving fast but catching up and fixing on them when they've stopped. –  OriginalDaemon Apr 27 '12 at 16:46
add comment

1 Answer

up vote 1 down vote accepted

Because your historical positions are recorded with delta time "baked in" applying any corrections on top of that seems excessive if not counterproductive. You don't want to change their values, but you do want to change how much the history affects the current target position.

This might work for you:

Pick an ideal framerate, say 1/30, and use that as a baseline to represent 100%. This 100% applies to how much the history affects the current camera target so at any framerate of your ideal 1/30 or faster your tracking acts as normal.

When your framerate slows down below 1/30 you want that 100% to drop so that the historical positions affect less and less of the camera's current target which will ease the camera closer to your target the slower the game is running.

share|improve this answer
    
Good idea. I'll try it later to see if it works. –  OriginalDaemon Apr 27 '12 at 15:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.