Delta Timing?
Blitz3D Forums/Blitz3D Programming/Delta Timing?
| ||
I know render tweening, but I have a physics tutorial that uses Delta timeing, but it does not show how to do delta timing. So my question is, what is delta timeing and how is it different from tweening? |
| ||
Well, in delta timing, you move entities based on the time passed. So, say you would move MESH_A one unit every second. So, when the next loop comes along, you work out the time passed since you last moved it, and move it a certain distance. For example: 1 unit per second Time since last time it was moved: 0.1 seconds So, you would move the mesh 0.1 units for that frame Next frame comes along, Time since last time it was moved: 2 seconds (Extreme example) Move the mesh 2 units for that frame.... etc etc Hope that helps. Btw, that's my understanding of delta timing. Their may be more to it than that :o) |
| ||
With render tweening your game logic runs a set number of times per second, say 20, and you use all the free processor time to update the display with objects at positions between the last two updates - faster machine->more tween frames->smoother. Delta time runs the game logic as many times per second as your machine can handle. The time between the last two updates (the delta time) is calculated and used to update the world in a way that will keep things running the same on different speed machines. If your delta time is t milliseconds, and you want it to move v units along x each update, you say: x=x+v*dt Deltatime has issues - I found it produced some jerkiness and found it hopeless for physics. I tried delta time for a crazy golf game. Any physics simulation accumulates errors with time, which often doesn't notice - the game feels right - but on my crazy golf game, given an equal power hit on two machines with different speeds the ball would travel very different distances up a slope. I remember Swift talking about a better method of deltatime but can't remember the details - perhaps he'll read this. This is the widely used version I think, tho. |
| ||
I have a little code sample from the tutorial. How could I make this work with tweening? Would I just not multiply that by deltaTime? InstVelocity\x# = acceleration\x# * deltaTime |
| ||
Get rid of the deltatime multipliers- probably best just to multiply by a constant you can tweak. You then need to implement tweening - see Mark's castle demo that comes with B3D. |
| ||
Check out how to use deltatime (frame-limiting) on my programming tutorial site. It shows two different methods (as well as a built in FpS counter). |
| ||
Thanks All. Wolron: I will. |
| ||
This is what I ended up using It works best as far as smoothing. apologies to who ever contributed to this. There are a few extra variables in the code. Looks like it's time to clean out a few of those ;for timing Global frames Global r_time Global fpscount Global render_time Global multiplier#=0.2 Global multiplier2# Global xspeed=10 Global AvgMultiplier# Dim AvgMult#(10) Global AvgMultiplierCount Global TimePerFrame# Global Second_Timer SetFrameRate(30) Const TARGET_FPS# = 30.0 Global previous% = MilliSecs() Global lastFPS% = MilliSecs() while now% = MilliSecs() delta# = (now - previous) / (1000 / TARGET_FPS) If delta <= 0 Then delta = 0.001 previous = now wend Function CalcTimer#() ms_passed#=MilliSecs()-render_time render_time=MilliSecs() multiplier#=(multiplier#*4.0 + Float(ms_passed#/ TimePerFrame))/5.0 If multiplier# >2 Then multiplier#=2 ;Get fps frames=frames+1 If MilliSecs()-r_time=>1000 Then fpscount=frames : frames=0 : r_time=MilliSecs() End Function ;initilalize timer Function SetFrameRate(FPS) TimePerFrame = (1000.0 / FPS) render_time=MilliSecs() End Function |