KnuckleCracker / CW4-bug-tracker

The gathering point for bugs and supporting information, or suggestions about additional features.
Creative Commons Attribution Share Alike 4.0 International
13 stars 1 forks source link

[4RPL] Sniper can refuse to fire at a custom unit for no obvious reason #379

Closed Regallion closed 3 years ago

Regallion commented 3 years ago

save.zip image

In this position the sniper will not fire at the dummy unit. If you move it even 1 tile south it will start firing. Reasons for why, unclear, appears to be a bug of some kind.

knucracker commented 3 years ago

Oh this wasn't pretty. It looks like the LOS algorithm used by the sniper could sometimes overshoot the target. It uses a DDA algorithm to hop from cell to cell and it pulls the triangles from the terrain at each 'cell'. It then checks for a ray intersection with the terrain triangles at each cell. For efficiency it assumes it will walk from the source to the dest and each cell will be the lower left vertex of a quad made of two terrain triangles. So far so good. The problem was that the loop that walked from the source to the target could overshoot the target because it didn't know the walk was being done and offset by 1 to the bottom or the right (so that each point was the lower left of a quad). That meant it might miss the target coordinates and the LOS check could keep going beyond the unit. In this case it would eventually hit the terrain and hit the range limit. And in either of those it would appear that the shot was blocked.

I've fixed this issue. This is a really fundamental thing and will affect snipers shooting at eggs, orbs, skimmers, and custom units. So I'm interesting to see what happens in the 1.0.2 build...