运动“算法"可以被称为“算法".在客户端服务器多人(MMO)游戏中? [英] Movement "algorithm" in client-server Multiplayer (MMO) Games?

查看:190
本文介绍了运动“算法"可以被称为“算法".在客户端服务器多人(MMO)游戏中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在写2D Flash多人游戏和套接字服务器.我对客户端和服务器之间的移动算法的原始计划如下:

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:

  • 每当这些改变时,客户端都会将播放器的移动模式(向前移动或不移动)和播放器的转弯模式(不转弯,向左转或向右转)通知服务器.
    • 服务器每隔几毫秒就会循环播放一次所有玩家,并根据时间差来计算转弯角度和移动距离.客户端执行相同的计算.
    • 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.
      • 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.

      我对客户端的当前计算(服务器中使用相同的数学运算法则)==>

      My current calculation for the client (same math is used in server) ==>

      转向

      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 -> 5, -5 -> 355, etc.)
              {
                  if (angle > 360)
                  {
                      angle -= (Math.round(angle / 360) * 360);
                  }
                  else if (angle < 0)
                  {
                      angle += (Math.round(Math.abs(angle) / 360) + 1) * 360;
                  }
                  return angle;
              }
      

      运动

      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)];
              }
      

      这似乎很棒.为了考虑延迟,服务器会不时地通过发送此数据来更正客户端的信息.

      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.

      使用此系统,很少的带宽用于处理移动.但是,我的服务器与客户端的坐标和角度之间的差异太大.我是否应该扩展我的算法",同时考虑到用户的延迟时间?还是在性能更好的客户端服务器多人游戏中有更好的方式来处理运动?

      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<>server multiplayer games with great performance?

      推荐答案

      我的初始设计与您的初始设计相似,但是如果这种设计不起作用,也许您可​​以允许客户端进行所有移动,而仅由服务器进行一些操作范围检查.

      My initial design would be similar to yours, but if that's not working, perhaps you could allow the client to do ALL the movement and just have the server do some range checking.

      因此,如果您上次报告的位置是X,则下一个位置必须位于X的半径范围内,该半径基于客户端发送的带有x,y数据的时间戳记之差.

      So if your last reported position was X, the next one must be within a radius from X where the radius is based on the difference in timestamps sent from the client with the x,y data.

      大多数情况下,这只是检测作弊所必需的.

      Mostly this is just needed to detect cheating.

      停止,战斗等需要与攻击一起发送位置,并且由位置触发的操作仅在客户端发送该位置的更新后才触发,但将基于服务器.

      Stopping, fighting, etc would require a position be sent along with the attack, and actions triggered by positions would only be triggered after the client sent the update for that position but would be server-based.

      不确定这是否有太大帮助,但它可能会停止您从初始算法中看到的颠簸重新同步.

      Not sure this would help too much, but it might stop the jolting resyncs you would see from your initial algorithm.

      评论回复:

      否,客户仍将其位置通知服务器,但服务器不会尝试计算下一个位置.这意味着服务器(和所有其他客户端)的位置至少要落后一个发送/接收周期.

      No, the clients would still inform the server of their position, but the server wouldn't try to calculate the next position. This would mean that the server (and all other clients) would be at least one send/receive cycle behind in position.

      我想我是说让客户做所有工作,弄清楚角色在哪里,然后告诉服务器,但是要包含足够的信息,以便服务器可以选择检查有效性以确保没有人作弊.

      I guess I'm saying just let the client do all the work, figure out where the character is and tell the server, but include enough info that the server can optionally check validity to ensure nobody's cheating.

      作弊检测甚至可以关闭以提高性能,也可以将其设置为随机检查.

      The cheat detection could even be turned off for performance or set to randomly check.

      注意:需要将与行程范围内的对象有关的所有碰撞/位置信息发送给客户端,以使其正常工作.

      Note: All collision/position info on objects within traveling range would need to be sent to the client for this to work.

      这篇关于运动“算法"可以被称为“算法".在客户端服务器多人(MMO)游戏中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆