且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在实时多人游戏中移动对象? (统一的Google Play游戏插件)

更新时间:2023-02-02 21:10:18

您可以尝试发送目标排名.然后,当您收到此目标位置时,可以尝试从当前位置插值到目标位置.这将使运动更加平稳,并且对网络的依赖性降低.同样,如果您的球完全基于物理原理,则必须传递速度和加速度.但是每隔几帧左右,您需要检查一下位置是否与另一个屏幕相距太远,并且可能需要将其捕捉回去. 对于更复杂和动态变化的运动,您必须进行一些预测.

You can try sending the target position instead. Then when you receive this target position, you can try to interpolate from the current position to the target position. This will make the movement more smooth and less dependent on the network. Similarly, if your ball is fully based on physics you have to send velocity and acceleration over. But every few frames or so, you need to check if the position is too far away from the other screen and you may need to snap it back. For even more complex and dynamically changing motions, you have to do some prediction.