Day Six

I spent two hours (which is longer than I should’ve spent working on the game at all today) trying to work out fast rotating collision detection for the hexagon’s sweeping beams today.

Fast moving rotating collision bodies are a tricky problem to solve! Games like the new Legend Of Zelda make this stuff look really easy, but it’s not. Collision detection in games is basically all about faking it with maths, because doing proper simulations is really computationally expensive.

Unity’s 3D colliders (which use PhysX) have a setting for speculative continuous collision, which should help with that in most cases, but comes at a performance cost. That cost is pretty small for me, since only the player has a rigidbody, and it only collides with the lasers. Everything else is my own bullet tech (which you can buy on the Unity Asset Store - n.b. this is an affiliate link which means I’ll earn a little bit of commission, but you won’t pay anything extra), which assumes all bullets are circles and don’t interact with each other, which makes it super speedy. There’s also some nice optimisation in that the player is always 15 units away from the centre, so I can just ignore any collisions that are less than 14 units and greater than 16 units from the centre.

However, for some reason it just wasn’t working. It did not want to register collisions on this laser while it was rotating. It works fine for the square and the pentagon, right? Both are static lasers so it must be the fact that they are rotating. I tried a bunch of different combinations of rigidbody placement, I tried changing the player movement code so it moves the rigidbody (which it technically should be doing anyway because Unity treats colliders that don’t have rigidbodies as static, so moving them by their Transform component invalidates a bunch of caching), and nothing was working.

Finally, I tried making the lasers static, with no rotation at all. Just a big sustained stationary laser. And…

It didn’t work 😂

Turns out it was just a stupid mistake I’d made 🙃 the code for enabling the lasers didn’t enable the colliders until the last bit of the animation. That was fine for the lasers in the square and pentagon levels, because they were very short lasers that didn’t stay on-screen for very long. There’s also a little bit of generosity - it only actually hits you if the laser hits you for more than a frame, which hid the problem even more.

Sigh. I am not a smart man.

Anyway, it works properly now - even with easing to make the animation itself look a little bit less rigid:

What’s next?

Tomorrow I’ll clean up the rest of the hexagon boss - there are a couple of really cheap shots that are almost un-dodgeable, I want to make the danger nachos a little more… dangerous, and the centre of the laser in the gif above is a square, not a hexagon (I watched this gif so many times while writing this post that it’s seared into my retinas).


I hope you enjoyed reading about my Polyfury progress. If you have any questions or thoughts, please feel free to leave a comment below. Thanks for reading, and maybe check out the demo:

Making your own games? Check out Artificer Pro - released this month!

Previous
Previous

Day Seven

Next
Next

Day Five