Speed based on time?
Blitz3D Forums/Blitz3D Programming/Speed based on time?
| ||
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? |
| ||
Check out frame-limiting on my programming tutorial in my sig. |
| ||
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#) |
| ||
FYI, my frame-limiting code uses delta time... |
| ||
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# |
| ||
Wolron, I misunderstood you - thought Fame-limiting is using a fixed frame time. |