Phantom Arrows | Stories from Beyond the Code


Welcome to the first Story from Beyond the Code!
The idea is telling about little stories that happened during development that I think are pretty entertaining!

So let's start with the PHANTOM ARROWS!
If you played the jam edition of the game (it's still available) you probably noticed the archers would often just shoot into the ground or the abyss; which is mad frustrating right?!
I spent half of the development time for the jam trying to solve it; couldn't. It worked enough. I spent at least a day on it during voting to fix it for the Post-Jam update. I barely fixed it because it was such a nuanced error.

At first I checked the obvious, the units targeting dead enemies. And they were just blasting dead enemies! Spirits got no rest. I fixed that pretty easily but the error was still happening; just not as frequently. I tried scouring the Archer tower code, the Archer unit code; I even dissected the enemy code and arrow code.

I went to the lengths of re-coding the code that moves the arrows. 

I couldn't stop these gods forsaken phantom arrows from appearing!
That's when it hit me!
If dead enemies in the target pool have been indefinitely solved. What also could cause arrows to linger? Because I have a lifetime code on them to disable. I have them in a pool so there's only 5 arrows per archer. I have a lot of fail safe code especially now to keep them on track. But during the arrow movement recode I only took off the " * delta" from non-perfect shots. This meant that the perfect shot arrows were being multiplied by delta TWICE. Which makes them really slow. This was the moment I had a breakthrough.

The endgame issue wasn't dead enemies getting blasted. It wasn't arrows not disabling correctly when hit or timed out. It was the fact that the perfect shot arrows will home in on their target. It doesn't matter where the target is at they're perfectly shot so they follow the exact coordinates of that target every tick.
And I never made it so these arrows could detect if their target was dead. So what was happening was 3 archers would shoot 1 arrow. One or two would get perfect shots producing these homing arrows. While the other archer(s) normal shots already killed that perfect shot arrow's target. Meaning while the enemy was removed from the target list; it wasn't removed as the perfect shot arrow's target it's still chasing.

The solution ended up being simple. Just make sure arrows can see if their current target is disabled each tick and handle it from there. Now the entire issue has been wiped!

Get One More Night...

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.