I would like to calculate peers speed. I recieve peer xy position at different time. Time depends on ping between me and peer so it could be between 20 and 500ms. Is it possible to calculate speed?
I am guessing you want to use ping time difference to calculate the speed of your object which was at (x,y) old and now is at (x,y) new?
Speed can be calculated by a division: distance / time.
You could create a new (x,y) pair which is the difference between old and new. That way you can calculate the distance the object has traveled. And divide this distance by the time (which was given by your ping) and you have the speed in pixels per milliseconds.
i want to use ping time difference to calculate the speed of my object. I think you gave me very usefull information. I will try to do this. Only one more thing, what is the easiest way to calculate ping time beetwen me and peer?
but it seems that I don't understand how comunication between two computers (ping) work. I thought if ping between two computer is 200ms and on both computer "allways" blast X,y position that me and peer will "allways" recieve new x,y position, just 200ms later. But it seems to me that I recieve x,y position from peer every 200ms and not allways.
Which thing is correct 1. or 2.?
1. ping 200ms - x,y position from peer is "allways" blasted to me - I recieve x,y position "allways" just 200ms later.
2. ping 200ms - x,y position from peer is "allways" blasted to me - I recieve x,y position every 200ms.
To be honest, I don't know, but it doesn't matter anyway.
I know that if you "blast" rather than "send", the messages aren't guaranteed to arrive in order or even at all, so maybe that has something to do with it (blasting is still the right thing to do though, because it's faster).
Also, don't "Always" send the position. Ideally, you should only be sending information when there is a change in input. For example, when a player presses an arrow key, send a message to peers; when the key is released, send another message. There's no need to send anything in between - you can just assume the arrow key is still being pressed.