Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在为本地比赛制作 MMORPG 游戏,我已经开始在服务器上工作,我遇到的问题是我想要一种方法来检测每个玩家看到的其他玩家,以便我可以发送有关他们周围玩家的信息给特定的玩家。
首先,我想将一个 2d 圆形对象附加到 Player 对象,并对数据结构中的每个玩家进行碰撞检查,但这会非常消耗性能,是否有合适的算法呢?请帮我!
您可以使用矩形进行手动检查,而不是使用圆形和碰撞检测库,这很好,因为您的屏幕和游戏区域可能是矩形的:
int dist = 100; if (Math.abs(a.x - b.x) < distX && Math.abs(a.y - b.y) < distY) { // send player b to player a
您还可以手动检查两点之间的距离,这就像使用圆一样,但会消除碰撞检测库的开销。
如果您的玩家移动速度不是很快,您可以每 10 个滴答声而不是每个滴答声执行此检查。