Note that there are some explanatory texts on larger screens.

plurals
  1. POMovement "algorithm" in client-server Multiplayer (MMO) Games?
    primarykey
    data
    text
    <p>I've been writing a 2D flash multiplayer game and a socket server. My original plan for the movement algorithm between the client and server was the following:</p> <ul> <li>The client informs the server about the player's movement mode (moving forward or not moving) and the player's turning mode (not turning, turning left or turning right) whenever these change. <ul> <li>The server loops all players every few milliseconds and calculates the angle turned and distance moved, based on the difference in time. The same calculation is done by the client.</li> </ul></li> </ul> <p>My current calculation for the client (same math is used in server) ==></p> <p><strong>Turning</strong></p> <pre><code>var newTimeStamp:uint = UtilLib.getTimeStamp(); //set current timeStamp var rot:uint = Math.round((newTimeStamp - turningTimeStamp) / 1000 * 90); //speed = x degrees turning every 1 second turningTimeStamp = newTimeStamp; //update timeStamp if (turningMode == 1) //left { movementAngle = fixAngle(movementAngle - rot); } else if (turningMode == 2) //right { movementAngle = fixAngle(movementAngle + rot); } private function fixAngle(angle:int):uint //fixes an angle in degrees (365 -&gt; 5, -5 -&gt; 355, etc.) { if (angle &gt; 360) { angle -= (Math.round(angle / 360) * 360); } else if (angle &lt; 0) { angle += (Math.round(Math.abs(angle) / 360) + 1) * 360; } return angle; } </code></pre> <p><strong>Movement</strong></p> <pre><code>var newTimeStamp:uint = UtilLib.getTimeStamp(); //set current timeStamp var distance:uint = Math.round((newTimeStamp - movementTimeStamp) / 1000 * 300); //speed = x pixels forward every 1 second movementTimeStamp = newTimeStamp; //update old timeStamp var diagonalChange:Array = getDiagonalChange(movementAngle, distance); //with the current angle, howmuch is dX and dY? x += diagonalChange[0]; y += diagonalChange[1]; private function getDiagonalChange(angle:uint, distance:uint):Array { var rAngle:Number = angle * Math.PI/180; return [Math.round(Math.sin(rAngle) * distance), Math.round((Math.cos(rAngle) * distance) * -1)]; } </code></pre> <p>This seems to work great. In order to take lag into account, the server corrects the client's info every now and then by sending this data.</p> <p>With this system very little bandwidth is used to handle movement. However, the differences between my server and the client's coordinates and angles are too big. Should I maybe extend my "algorithm", to also take into account the latency a user has? Or are there better ways of handling movement in client&lt;>server multiplayer games with great performance?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload