• Twitter
  • Facebook
  • Google+
  • RSS Feed

Tuesday, 17 February 2015

Interactivity 5- Making our spaceship shoot + importing asteroids

No comments:
 
During our 5th lesson of interactivity we continued working on the laser beam for our game and later worked on importing an asteroid and making it float within the space.

We began by making a piece of coding called 'Mover', which will allow our laser beam to move on the game.


'Mover' code in game. 


Code for the mover script.

We then made a new prefab and called it 'Bolt' from the bolt currently on our game. Making the bolt a preset means that I can use more than one bolts without having to keep making a new object.


'Bolt' Asset. 


Multiple bolts added to my game.

We then made an empty object called 'SpawnPoint' to position our bolt. The piece of coding we used allowed the bolt to reload and shoot from the spawn point's position.


We then attached the bolt to the spaceship so that it was connected to the ship, meaning when the bolt shoots out, it will come from the front of the ship where the spawn point is.


SpawnPoint for the bolt attached to the ship


Making the empty object already attached have the 'Bolt' asset. 

The next piece coding we added allows us to change the fire rate as previously the bolt would constantly shoot from the ship.


Constant bolt fire resulting in hundreds of clones being made. 

The 'nextfire' piece of coding allows there to be a gap between how quickly the bolts shoot out.

Coding for change the fire rate so its not constant. 


'FireRate' set to '0.2' so that the rate of fire is not too slow but not too fast. 



                                        Video example of the spaceship working in game. 

We then created a boundary so that the bolt dies after it leaves the background rather than there being lots of bolts constantly moving away from the game. The boundary was named 'DestructionBoundary'. The piece of coding we used beginning with 'Destroy' allowed the bolt to be destroyed as it leaves the boundaries of the game.


Beginning of our boundary. 


Boundary made invisible, yet active around our game. 

'DestructionBoundary' Script in game


Coding to destroy the bolts as they leave the screen.

After this we made a new object called 'Asteroid' and imported an asteroid model onto our game. We then added a 'Capsule Collider' around the asteroid to make the asteroid move.


Asteroid on our game


'Capsule Collider' placed around the asteroid to make sure it can move. 

We then created a new script called 'RandomRotator' which will make the Asteroid turn during the game. The code was then dragged onto the asteroid. The game was then previewed and the asteroid moved accurately.


'RandomRotator' code in game.

'RandomRotator' code.

Next lesson we will be working on destroying the asteroids and adding explosion effects when the ship and asteroid explode.

No comments:

Post a Comment

 
© 2012. Design by Main-Blogger - Blogger Template and Blogging Stuff