Hi, I am doing a 2 player 2d racing game (network peer to peer), and I am having small teleportations (because of lost packets, or whatever). It is important to note that the "other" player is not inserted in the box2d world. I did it like this because I didn't need interaction between the two players. Now the problem is that I must predict the position.
I have the clock synced between the two players, and I was thinking that maybe just with horizontal/vertical speed and maybe taking into account gravity I should be able to do a decent prediction. I want the game for local network for smartphones, and the teleportation is more like a vibration (small) so I think acceleration is not needed.
I think it should be something like
input => gravity, received position, received horizontal/vertical speed, timestamp of packet (from the peer), current time.
Output => current position.
I think I should calculate the "speed vector" from the h/v speed and then with the elapsed time convert it to a distance vector and apply it to the received position, but I don't know how to calculate with gravity here (not sure if needed anyway, because most of the time movement is more in horizontal).
So if someone has worked with this kind of prediction, first is there a better way of doing this? And is what I am describing above the correct steps of doing it? I will post code when done specially if the results are bad. Also how should I add the gravity to the ecuation?
Note: I've already tried prediction doing extrapolation with the positions of the last 2 received packets but most of the time there was a division by zero because there wasn't enough time passed so I discarded that option.
I have the clock synced between the two players, and I was thinking that maybe just with horizontal/vertical speed and maybe taking into account gravity I should be able to do a decent prediction. I want the game for local network for smartphones, and the teleportation is more like a vibration (small) so I think acceleration is not needed.
I think it should be something like
input => gravity, received position, received horizontal/vertical speed, timestamp of packet (from the peer), current time.
Output => current position.
I think I should calculate the "speed vector" from the h/v speed and then with the elapsed time convert it to a distance vector and apply it to the received position, but I don't know how to calculate with gravity here (not sure if needed anyway, because most of the time movement is more in horizontal).
So if someone has worked with this kind of prediction, first is there a better way of doing this? And is what I am describing above the correct steps of doing it? I will post code when done specially if the results are bad. Also how should I add the gravity to the ecuation?
Note: I've already tried prediction doing extrapolation with the positions of the last 2 received packets but most of the time there was a division by zero because there wasn't enough time passed so I discarded that option.