Collisions

From WinBolo

(Difference between revisions)
Jump to: navigation, search

Sticks (Talk | contribs)
(initial creation)
Next diff →

Revision as of 23:16, 13 May 2009

Contents

Collisions

The Way They Are

As of 1.16, tank collisions are handled completely on the client side. Depending on if a tank has collided, it's position and speed is adjusted. Thus, through the adjustments in a tank's speed and position does collision become related to the server.

Each game tick a function playersCheckCollision() is called, found in the players.c file.

  • The world x and world y coordinates (via bit-shifting of the tank's map coordinates) of the player's tank are matched up against every other active tank's world x and world y coordinates.
  • If the distance between the axis of the tanks is less than 256 (there are 256 world coordinates in every map tile), then it was denoted which value is larger: the tank's component or the other tank. Using the Pythagorean Theorem, we can see that the furthest distance in which tanks would collide can be about 362 world coordinates (a = 256, b = 256, c = 362). This equates to about 1.4 map squares, which is a problem. More on this below.
  • Going back to the tankCheckGroundClear() function called - found in tank.c - the actual adjustments are made to the tank.
    1. The tank speed is reset to zero.
    2. If the player's tank is south of the tank that it's hitting, we move it's position due south by eight world coordinates. The same thing goes for any other direction. For instance, if the player's tank is east of the tank it's colliding with, the player's tank is moved eight world coordinates east.
    3. If the distance of either component (x or y) was less than half a map square away, a rand() function was called to try and move the tank out of the way. This comes about (mainly) because of starts. If you'll notice when a bunch of players join at once and spawn in the same spot, they seem to "dance" around until they are not colliding anymore. The dancing is a result of the rand() function calls.

Quick Fixes

Permanent Fixes

Personal tools