top of page

Player Control Script

  • Sheng hao Wang
  • Apr 1, 2016
  • 1 min read

With the play area set up, now I need to add player Control script to move the player spaceship.

First step would be writing the movement function.

There is a bit complication while writing this script, due to the coding difference between Unity 4 and Unity 5. Because of the software upgrade the tutorial script is somewhat obsolete, but the tutorial site has the upgraded documentation to solve this.

So instead of write code

rigidbody.velocity = movement;

the correct way in unity 5 is

GetComponent<Rigidbody>().velocity = movment;

After testing the player movement script, it clearly shows the speed of the space craft is moving way to slow for the game. So adding the speed function to the script would be the next step.

Punch in the speed value in the inspector and test.

After fixing the speed issue the other problem came up. The spaceship is flying off the edge of the game area. To fix this I need to add some line in the script to limit the spaceship in the game area.

Now the boundary function is added in the script, however it could use some cleaning up. To do that I added a few more line to clean it up.

With the boundary related function clean up in the inspector, it is time to add value and test it.

The player ship control is pretty much finished, but ship tilt will add a nice finishing touch for the player spaceship control.

Now the player movement is finished, the next step will be adding shooting mechanics into the game.

Comments


Featured Posts
Recent Posts
Archive
Search By Tags
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square
bottom of page