Movement-algoritm over the network ?

Started by
27 comments, last by grumpymonkey 14 years, 10 months ago
Quote:Original post by oliii
in the article, they take a sample back in time by (t - updaterate * 2). So it means that until you receive the next scheduled update, you will be interpolating. If a couple of packets are delayed / lost, you will be extrapolating a little.

That occurence would be pretty rare in normal conditions.

Ah now I get it!
What a cleaver way of doing it, lol.

I think I finally got it, just gonna read that article in and out and then experiment a bit !

Thank you once again!

Advertisement
Ok, so just to make sure Im doing this right:

I've got three positions (P0, P1, P3) stored in a buffer at (T0, T1, T3), just like you said.
Then my updaterate is every 50 millesecond (my Tu, right?), so its 20 updates / second.

And now, correct me if I'm wrong:
The position of the object at time T is then P1 + (P2-P1) * (Tcur - t2) / Tu.

The "time" we are talking about, is just a counter going on in the background which is synced between clients and the server, right?
So lets say that T0 = 100, T1 = 150, and T2 = 200.
And just to make it simple, we use only one axle in the position (lets say the X-axle):
P0 = 10, P1 = 22, P2 = 34.

So now, I want to interpolate between P1 and P2 to get a smooth movement.
How should I do that? Should I calculate that equation every millisecond in the loop to get the position at exactly that tick, or what?
Because I want to interpolate for 50 milliseconds until my next update arrives, right?

And also, how would the equation look like if I want to calculate the position at say the 157th tick (or any tick between T1 and T2)?
You don't calculate it every millisecond, unless you have a frame rate of 1,000 :-)
enum Bool { True, False, FileNotFound };
Quote:Original post by hplus0603
You don't calculate it every millisecond, unless you have a frame rate of 1,000 :-)


Ok lol, so how often should I calculate then ?
My framerate is locked to 60 btw.

And also, can you please help me with my previous questions, because I do understand the logic behind it, but not really how it should look in the equations and so...

Because I really don't understand how to use the equation you gave me. :/

[Edited by - pjuke on June 9, 2009 2:04:54 PM]
Quote:I really don't understand how to use the equation you gave me. :/


It sounds like you're taking water over your head. I suggest you step back and work on learning the fundamentals first.
enum Bool { True, False, FileNotFound };
Quote:Original post by hplus0603
It sounds like you're taking water over your head. I suggest you step back and work on learning the fundamentals first.

Well, I guess I don't explain very well.

Ok look:
The position of the object at time T is then P1 + (P2-P1) * (Tcur - t2) / Tu.
Lets say I've got:
P0=10, P1=25, P2=40
T0=100, T1=150, T2=200
Tu = 50

And now I want to interpolate between P1 and P2.
And I don't really know if I'm doing something wrong here, but check this out and tell me if it's ok or not:
25 + (40 - 25) * (240 - 200) / 50 => 32
It gives me the position 32, reasonable or not? Seems OK to me since it's > than P1 and < P2.

And ofc, when we take tick 250 (when my next update should arrive), it will end up on P2:
25 + (40 - 25) * (250 - 200) / 50 => 40

But what if I take a earlier tick, lets say 230:
25 + (40 - 25) * (230 - 200) / 50 => 24
It gets below P1. It is here where I get lost, is tis possible or not ?
Quote:25 + (40 - 25) * (230 - 200) / 50 => 24


*cough*34*cough*

Also:
Quote:25 + (40 - 25) * (240 - 200) / 50 => 32

Is 37.
Quote:Original post by Antheus
Quote:25 + (40 - 25) * (230 - 200) / 50 => 24


*cough*34*cough*

Also:
Quote:25 + (40 - 25) * (240 - 200) / 50 => 32

Is 37.

Dude, I just realized I counted all wrong, shame on me, thank you for showing :)
But OK, I got the equation to work, finally.

But just to make sure I'm doing another thing right, its about the timestamp on the packages.

Lets say Player1 presses the FORWARD key, which is sent to the server at tick 200.
Then the server receives it and sends it back to Player2 with a timestamp, now, this timestamp should be the timestamp it got from Player1, right? That is 200, correct me if Im wrong.
I just use a variable for each type of movement.
eg.
0 = stop
1 = left
2 = right
3 = jump

then I use a timer to update the exact position every couple of seconds. that will sometimes look choppy, but you could use a path-finding algorithm to make the other players move to the updated position. that way it will look smooth, and everyone will end up in the right place, but if your making a fast paced game where all the players need to interact then you have to be more precise

This topic is closed to new replies.

Advertisement