Anybody know any Lua? You might remember Red Alert, the little shmup I’m developing for the PICO-8 fantasy console? Well, I’m getting close to actually having it in a playable state but I’m currently stuck with this one bug I can’t quite fix. You see, I built in this boss enemy that uses a laser beam and something is off with the collision detection for it. I am checking whether this beam intersects with a hitbox on the ship and it works most of the time, but there are edge cases with false positives. Here’s an example where the algorithm thinks the beam intersects with my ship:

This is a companion discussion topic for the original entry at

I think the collision detection for the left side of the hitbox uses wrong coordinates.

Note, how you are using obj.x,obj.y and obj.x,obj.x+obj.colw for the endpoints of left side of the hitbox in

if linecol(phx1,phy1,phx2,phy2,obj.x,obj.y,obj.x,obj.x+obj.colw) then return true end

Here, the second endpoint of the left hitbox side is obj.x,obj.x+obj.colw, which is wrong, as you are using obj.x+obj.colwfor the endpoint’s y-value.

This should certainly be obj.x,obj.y+obj.colh, as in:

if linecol(phx1,phy1,phx2,phy2,obj.x,obj.y,obj.x,obj.y+obj.colh) then return true end

I didn’t test the fix, thought…

1 Like

Holy shit! That worked! Thank you so much! I was staring at that code for two days and couldn’t figure it out!!!