Laser Squad [Day 39] – Firing calculations

After couple of days thinking about how to implement this feature, the first part of the algorithm is finished – the destination tile is marked where the bullet or the item (in throwing mode) could end up. What’s missing is testing tiles between the origin and the position for anything that could interrupt the calculated trajectory (units or concrete tiles). That part can easily be done by including units position testing in the LOS algorithm.

How it all works so far? First a random number is generated between 0 and 100. Then the accuracy of the weapon fire mode is taken and aligned in the middle of the range; meaning if the accuracy is 30, we consider that the target has been hit if the generated number is in the range from 35 to 65. If our generated number is in that range, target tile has been hit (handling different unit sizes is not implemented yet). If our generated number is lower than 35, we are missing the target tile to the left, or if greater than 65, we are missing it to the right. In case when we are missing the target, the units heading is also valued to determine if the missed target tile is horizontaly, verticaly or diagonaly away from the tile we actually fired on. At last, when we know the coordinates of that missed tile, we are extending the trajectory further until we hit the end of the map in that specific direction. Now the calculated trajectory is completed, all we have to do now is follow that trajectory and test if the bullet is hitting anything on it’s way.

 

* * * * *