# Extrapolation, i have yet to cover this in maths :D

Hello Blender artists!
This particular question refers to any single person who has done a level maths i beleive!
I am looking to add extrapolation to my game networking, but i cannot find any information on the whole system. Essentially, the client will receive positions of the other client at a specified interval.

With that, you can work out the vector of movement and the velocity along that vector.
What i am unsure of is how to continue.
Here is some of my sample code.

``````import bge
from mathutils import *
cont=bge.logic.getCurrentController()
own = cont.owner

before_last = [Vector([0,0,0]),timeA]
last_position = [Vector([0,2,0]),timeB]

path=last_position-before_last
velocity = path.magnitude/(timeB-timeA)

direction = path.normalized()
direction.magnitude = velocity
newposition = last_position+direction/60
"""
How can i use this over multiple logic ticks, when i am not receiving data?
"""
``````

If You set both position and calculated speed then bullet would do the rest of the jobb.

If the object don’t have physics It is trivial to calculate Yourself. Each tic:

newPos = oldPos + direction / 60 # if You use 60 logic tic per second.

odlPos and newPos should be Vectors.

Assuming distance_using_velocity should be just velosity in Your exampel and timeA and timeB is in seconds. … Hmm… more bugs in the code… The vectors should be subtracted - not summed, and You should take the magnitude of path when calculating velocity…

Oops, typo! yes they should be subtracted

To really sync things up over a network the problem is a bit bigger thou… The real problem is to translate a logic tic into a virtual ‘real’ time (to get the timeA and timeB right). Using real real time is not good enough unless fps is 100% steady at max. It can go like this:

Logic tic 1
Frame 1
Logic tic 2
Logic tic 3
Frame 2
Logic tic 4
Logic tic 5
Logic tic 6
Frame 3

All logic tics is virtually still 1/60 seconds, but logic tic 2 and 3 resp 4, 5 and 6 may in real time be immediate after each other while the real time between 1 and 2 resp 3 and 4 may be much longer.

We cant sync the logic tics over the network so network have to sync by real time.

I wonder if there is a api for getting the virtual time of the current logic tic - I’m quite sure BGE keep track of it internally.

Else it an interesting python problem - but it will not be as efficient or precise as getting at the internal tracking.

I’m not sure why not. I would use time.ctime(), and get the delay by halving the time it takes to send a packet to the server and receive a reply packet