lua - Corona SDK position prediction -
i using corona sdk create multiplayer game. each device sends 15 messages per sec containing position of character. results in choppy motion because messages take different times received , sends 15 per sec in 30 fps game. how take difference in position or rotation of character previous frame current frame predict position if no info received in next frame. open other solutions too! thanks!
if send rate fixed , known both parties (sender , receiver), receiver can assume it. in case, dead reckoning well-established technique easy apply. example, if sender sends info every 1/15th second, receiver can assume that, after first packet has been received, other packets 1/15th sec apart. if not received after 1/15th second, receiver makes guess info @ 1/15th sec if had been received. when packet comes, corrects guess.
the thing guarantee order of packets, , delivery. if packets never drop, , there in order (i.e., tcp), you're laughing.
if order guaranteed dropped, receiver needs know when drop occurred. think corrected via counter part of packet. if receiver gets packet counter = x, , next packet has packet = x+2, receiver knows packet dropped because order guaranteed, time delta between 2 2/15th second.
if no dropping order not guaranteed, counter help there too: receiver guaranteed if x has arrived, x+1 arrive eventually, if gets x+2, should save x+2 , wait till x+1 arrives.
finally, if neither delivery nor order guaranteed (the case of udp packets on wan), 1 time more counter sufficient, algorithm changes: if gets packet counter=x, , gets x+2, mean x+1 has been dropped, or arrive shortly, there no way know. receiver wait little amount (maybe 1/15th second) if x+1 hasn't arrived then, declare dropped (so if arrive ignored).
the near-constant frequency of sender critical in above.
lua corona multiplayer
No comments:
Post a Comment