Noob question in relation to Delta Timing

BlitzMax Forums/BlitzMax Beginners Area/Noob question in relation to Delta Timing

WiredWorm(Posted 2010) [#1]
Hi,

Sorry for the noob question but this is the first time i've tried developing a game using something like BlitzMax.

I've got some sample routines written which i've just applied fixed rate delta timing too - the samples will be shared amongst several of us to fine tune values that control the movement of the ship - I figured without delta timing the exercise would be pointless as each persons PC would most likely play the code at a different rate.

My understanding is that the delta timing code i've got ensures that the logic routine is called every .01 of a second and as this is responsible for updating the game environment it's quite ok to render whenever possible because at worst this will cause non-moving frames to be rendered.

However, here's my question....

If i'm trying to give the impression of acceleration within the game how is this best handled?

In the past I would simply have velocity values for the X and Y axis and have the system increment these values (up to a maximum) whilst the appropriate key was being held. This value would then be added to the X or Y position of the object.

Of course though this means that the movement is not smooth - with a maximum velocity of 5 you could potentially have the object skipping 5 pixels at a time which might achieve the aim but it doesn't look smooth.

Can someone explain how this should be handled? I have a feeling it involved the 'tweening' that i've heard mention of elsewhere but i'm not sure how to implement this in my code.

All comments appreciated.

Many thanks


explosive(Posted 2010) [#2]
Hi WiredWorm,

adding values of your velocity to your actually position is exactly the way it is done. I just can imagine three faults why it's not looking smooth:

1) when you run it in windowed mode then your OS keeps the frame rate down (depending on the os it's something between 25 and 40Hz).
2) your routines are too slow. Which can easily happen. Then you have to optimise your code.
3) Your timer is not set correctly. Just try to measure the FPSs and see how fast your programme really runs.


matibee(Posted 2010) [#3]
Are you sure you're updating at 100 FPS? If you're running with vsync enabled (which I recommend btw) it'll be limited to your refresh rate. 60Hz is common which will make your game appear to be running in slow motion or depending on how you handle the 0.01 timing, make it skip and jump while it tries to stay inline with a lower frequency. I don't agree with eplosives point (1) as it's quite possible on the right hardware to run windowed or fullscreen blitzmax apps at 1000 frames per second if vsync isn't enabled.

If you know the update delta time (0.001 * milliseconds_elapsed, whether milliseconds_elapsed is fixed or fluctuating) increasing velocity is as simple as velocity :+ (100.0 * framedelta). Which increases it by 100 pixels for every full second (one second takes it to 100, 2 seconds takes it 200 and so on). Movement is then X :+ velocity.

The above is constant linear acceleration of 100 pixels per second. If you want to do real acceleration (which is a function of time^2) keep a track of the time it's been applied, and use that to work out how much to increase velocity..

age :+ framedelta
velocity :+ (9.8 * age * age) ' hey it's gravity: m/s^2. We should have a terminal velocity too ;)

If velocity is 5 pixels per frame then so be it, it happens, and it can be smooth if the timing system plays nice.

Cheers
:)