Mini-Update; Debugging Hit Detection

I noticed hit detection was a little scrambled, and since it’s a huge part of the game, I decided to spend today digging into why. It’s been a frustrating, but educational experience.

I’m noticing more and more that code I wrote towards the start of the year tends to be garbage. To be expected, given I’d just started learning C#. Basically, as soon as a round struck an armour plate, it was immediately jolting ~25° clockwise, throwing off any actual damage calculation. I ripped that code out, and put in some much simpler logic, using the actual physics rather than a hack-y workaround.

If a round is supposed to pierce, it basically freezes in place when it strikes, allowing the damage calculation to be done properly without pollution. It’s then removed. If it doesn’t pierce, it either explodes without causing damage (absorbed) or ricochets off (deflected), depending on the angle.

Unfortunately, I’ve now discovered another weird little bug. As you can see in the screenshot above, I flicked on my verbose debug output for the projectile. It’s running the right logic; the round is decaying in penetration strength because of how far it’s travelled, it’s figuring out how much the angle of the defending armour is affecting effective armour, and then comparing the two. But, bizarrely, it’s thinking 15 is more than 286.

EDIT: I got to the bottom of it. The logic for angle of impact was overriding everything, so even when a shot definitely should penetrate, if it was at too parallel an angle, it was just deflecting, making even rear shots at an angle impossible. I re-ordered the checks, and increased the threshold a little. Angle of impact now determines whether a non-penetrating shot bounces or is absorbed.

On a different note, I got this really cool book for Christmas, from The Tank Museum in Bovington. It’s creatively called “The Tank Book”. Bovington is a really fantastic place, and if you’re ever in the UK I really recommend checking it out.

I was there last year, and saw the last living Tiger I tank – Tiger 131 – in action. I also saw a number of other vehicles, including the real M4A2E8 Sherman from the film “Fury” which was a hugely cool thing. They have a ton of vehicles, including a British WWI Mark V tank, a German WWI A7V, a whole heap of T-series Soviet tanks, and just a warehouse full of conventional and unusual vehicles.

I’ve yet to sit and flick through it, but I noticed a lot of really useful interior reference. Always good to ground your designs in the real thing; form follows function, after all!

Leave a comment

Design a site like this with WordPress.com
Get started