Friday, 22 January 2016

Asteroids in Unity pt 1

I've started watching Ants youtube tutorials on making the classic game Asteroids on Unity. I have the basic code for making the ship move around the playable area, and I have all the sprites installed.
I'm focusing on the coding side of things on this project with my goal being able to recreate another simple game using only my own knowledge.

   Above is the 'PlayerController' script I made, it allows me to control the spaceship using the w,a,s, and d keys. To move upwards I press 'w' and to move downwards I use 's'. I use 'a' and 'd' to rotate the ship left and right.


This is my 'MovementWrap' script, it keeps the ship in the cameras view by wrapping the screen edges. Its similar to the effect used in pacman when the player exits the screen on the right only to appear again on the left. Without the code the player would just fly away and get lost in an invisible void.

To get this code to work I found the position of the edges of the screen and then told the ship to teleport to the other side, for example 'if (transform.position.y < -4.2f) pos.y = 4.2f;'. I like to picture it being a room with 2 doors, and when you leave through one it teleports you to the other, meaning you are trapped in the room.




No comments:

Post a Comment