The next par of my asteroids game, was to code in a laser, so that the player can shoot the objects.
I added a box collider and rigidbody to the laser so that it would collide with other objects and wouldnt fall off the screen.
![ezgif-4203596147.gif](https://bethanycassap.wordpress.com/wp-content/uploads/2016/01/ezgif-4203596147.gif?w=642)
I then added a button to the laser and player controller so that when the space or “jump” button is held or pressed, a laser spawns into the game.
At the minute it looks rather messy, but it will be fixed with more code.
![ezgif-1704633167.gif](https://bethanycassap.wordpress.com/wp-content/uploads/2016/01/ezgif-1704633167.gif?w=642)
at the moment, the lasers are spawning in a random location and they need to be spawning from the ship, so I changed the code so they would spawn on the location of the player ship.
However, both have collisions and so they end up bouncing off each other and making the ship spin out of control.
![ezgif-449765919.gif](https://bethanycassap.wordpress.com/wp-content/uploads/2016/01/ezgif-449765919.gif?w=642)
I have then fixed the code for the bullets so that they can only spawn every so often and not every single time the space button is pressed or held and so that the bullets dont effect the players ship.
![ezgif-737012134.gif](https://bethanycassap.wordpress.com/wp-content/uploads/2016/01/ezgif-737012134.gif?w=642)
18/01/16
Continuing on from last week, I am starting to add the asteroids into the game so that there is something else other than just the player ship.
I added a rigidbody and collider so that if it touches anything else, it will bounce off it and continue moving. This will help me when I make it split when a laser hits the object.
![ezgif-1619493615.gif](https://bethanycassap.wordpress.com/wp-content/uploads/2016/01/ezgif-1619493615.gif?w=642)
I then added a spawn timer so that after three seconds, an asteroid spawns into the game. However, they need to stop spawning after a certain amount of time otherwise this happens.
![ezgif-2314463708.gif](https://bethanycassap.wordpress.com/wp-content/uploads/2016/01/ezgif-2314463708.gif?w=642)
Now that I fixed the asteroids spawning time, I then changed it so that they wouldnt all spawn in one place, but in a random place around a point and then move into the screen.
![ezgif-2032524352.gif](https://bethanycassap.wordpress.com/wp-content/uploads/2016/01/ezgif-2032524352.gif?w=642)
Next I added a collision onto the asteroids so that if the player touches them, they will be destroyed and so that the asteroids dont actually hit each other either.
![ezgif-3701737800.gif](https://bethanycassap.wordpress.com/wp-content/uploads/2016/01/ezgif-3701737800.gif?w=642)
I have then added some code into the game so that when I shoot the laser, it destroys the asteroid and the laser also disappears from the game.
I then made the lasers destroy themselves if they disappear off screen if they have missed an asteroid.