Thursday, 1 January 2015

Game Encounters: Powerup Scritping

02/03/2015


Powerup Scripting



This week I started scripting my powerups for the game. However I was forced to hold back on the enemies the Homing Missile, the False Power Up and the Spinning Blade.


















This was due to the fact that these would be deemed as secondary enemies and due to the fact they don't fire any ammunition it would take even more time to include them within the game.



So I moved onto the Powerups in Unity by exporting them as obj files. I did find complications at first as I had to rearrange them in Maya to make sure they were facing the correct axis (z,x) before exporting them again into unity and continuing. I also had to resize them and create new prefabs as their imported scale was too large for the level.

I can now finally get started on scripting. I started following a tutorial on the Unity website on making powerups randomly spawning within the game (http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/infinite-runner). 

I followed the tutorial by creating a prefab, creating a spawning script and a sphere and merging them all together. Now I can drag my prefab onto the scene and the powerup randomiser will appear. However the script didn't play out like I hoped it would. 

Instead of appearing randomly on the screen it instead switches between the powerup prefabs attached to the script. This as it turns out to be a happy accident as it adds new playability and challenges to the game.












I continued from there by starting to script for the shield powerup. I attached the shield sprite to a plane and then attached it to the player ship. This allows the sprite to appear and move with the player when the powerup item is collected and activated.

I first wrote a script for the shield Powerup collectable. I wanted to make sure that the collectable only recognises the player tag and identifies the Shield Sprite Script which I would write later. I also wrote destroy so that the collectable would be destroyed once triggered, so it cannot be reused. I then attached the script to the Shield resized prefab. 



I then moved onto the Shield Sprite Script. The problem I had originally was the sprite would appear and function as soon as the game started and not when it was called upon by the collectable being destroyed. I added myShieldSprite.SetActiveRecursively(false);  in void start to make sure that the Sprite was inactive when the game starts. 



I then made sure that under OnTriggerEnter that the script recognised the player tag as well as the Shield Script I wrote earlier. I then added myShieldSprite.SetActiveRecursively(true); to allow the Sprite to become active then the collectable has been destroyed.  I then added a IEnumerator to make sure that the collider and rendering were functioning properly when called. 



I tried using these script templates to work on the bomb powerup, but having little luck. I also tried it on the boost powerup, but decided to scrap the powerup all together as the level size is too small to allow excessive speed and would be irritating for the player to control.











No comments:

Post a Comment