Speed based on time?

Blitz3D Forums/Blitz3D Programming/Speed based on time?

EvilMeowChi(Posted 2005) [#1]
Im working on an online game and it occurred to me while testing it with my cousins slow computer that not all computers will run the same speed. Right now when i move an entity i do it by frame, like moveentity,0,0,speed# or whatever. What would be the best way to base movement speed on time instead of by frame?


WolRon(Posted 2005) [#2]
Check out frame-limiting on my programming tutorial in my sig.


jfk EO-11110(Posted 2005) [#3]
I'd suggest to use socalled "delta time". It will work with most machines, no matter how slow they are.

Each frame you cacluate the time that was required to render everything. Then you multiply your players waking speed variable with this time parmeter.

eg

t=millisecs()-16

while game
t2=t
t=millisecs()
delta#=float(t-t2)/16.6
...
moveentity player,0,0,stepsize# * delta#
...

Additionally you can use delta to adjust the animation speed of all AnimMeshes automaticly:

Updateworld(delta#)


WolRon(Posted 2005) [#4]
FYI, my frame-limiting code uses delta time...


Wayne(Posted 2005) [#5]
Yes, make it time based.

Determine the scale, Lets say the scale is ten blitz units equals one meter, and your velocity is two meters per second.

Each frame you move based on elapsed time of previous frame.
moveentity player,0,0,vel#*delta#*scale#


jfk EO-11110(Posted 2005) [#6]
Wolron, I misunderstood you - thought Fame-limiting is using a fixed frame time.