Home > other >  The distance between the groups of an algorithm: how to retrieve?
The distance between the groups of an algorithm: how to retrieve?

Time:03-31

Suppose we have a game scene:
There are n players, the server needs to know the distance between the players and other players, players in range is obtained, and the judgment of the,
Assuming that this scene occurred on the server, and no third party libraries support, so how to judge yourself algorithm,

CodePudding user response:

To receive each character position of the current frame and then direct the distance between the calculation point not to go

CodePudding user response:

Distance formula: SQRT ((x1, x2) * (x1, x2) + (y1, y2) * (y1, y2) + (z1, z2) * (z1, z2))
Unity calculation: (playerA. Tranform. Position - playerB. The transform. The position). Magnitude

, but in general, use the distance not attack other players within the scope of direct to judge, because there is a better way, such as using Physics. OverlapSphere to ball detection, retrieve the spherical layer within the scope of the specified object, there are other ways, too,,

CodePudding user response:

Again, for example, use of trigger collision detection, sets the collider to trigger mode (not A physical collision), when A collision detection scope of object into the B, B will be affected by the news, and then maintain A list of can attack, as A left or died or become an attack (such as eating the invincible), in the list to remove A,,,,

Way too much,,, to the comprehensive performance of various factors such as comprehensive consideration,

The worst is, enumerated all the players, and calculate the distance between them, and four players to compute AB, AC, AD, BC, BD, CD6 time,,,,, the more players, the greater the amount of calculation,
  • Related