Procedurally Generated Asteroids!
I added procedurally generated asteroids! It makes the asteroids level much more interesting. I will probably add the chance for more interesting things like lazer satalites or magnetic probes or something later. Either way, never see the same Asteroids level twice!
The size, orientation, initial rotation, direction, and mass of the asteroids are generated each round. The mass is based on the size of the asteroid so smaller ones will be easy to push around. Currently the algorithm is based on size. It feels pretty good. I wonder if the most accurate mass algorithm would be something like size3 or something. Dunno, what do you guys think?
For anyone interested in the positioning algorithm, here is what I did. First I pick a random number between 0 and 13. that is how many asteroids can show up for this round. Then I randomize the size between two constants. Then I check at random points withing the screen dimensions to see where I can put an asteroid where it won’t cause trouble. If the space is clear then I generate the asteroid. If not, I go through the loop again with a different set of data. To check if a position is clear I use a sphere check to make sure it did not collide with another asteroid. If it did it would send them both flying away at warp speed causing a chain reaction with the other objects turning the asteroid field into grenade shrapnel and the round would end in a very explosive tie. The sphere check has it’s size modified to the size of the asteroid to make sure that we are checking the bounds properly. I could have just used the maximum size of an asteroid to do my sphere checks but then the generation wouldn’t be as dynamic and random. For instance you would never see three tiny asteroids sitting next to each other. I wanted the spawn points to be protected too, so players didn’t spawn inside a giant rock. In order to do this I put a collider around the start point flagged as a trigger so that nothing would collide with it but the sphere check. I also had to mask out some other triggers I was using for gameplay reasons.