Tuesday, 10 January 2012

Project 3: Gauntlet Clone, Player Creation

The first thing I did to create my player was create a plane in Unity. As the game is going to be mainly 2D minus the 3D Walls I don't need to create a cube to represent my player, the game is going to be top down so this pretty much means the player is only going to be allowed to move along the x and y axis.
The first script that I entered for my player was a script to move it Left, Right, Up and Down,
Here it is;


function Update () {
if(Input.GetKey(KeyCode.UpArrow)) {
print("Up Pressed");
}i
f(Input.GetKey(KeyCode.DownArrow)) {
print("Down Pressed");
}i
f(Input.GetKey(KeyCode.LeftArrow)) {
print("Left Pressed");
}i
f(Input.GetKey(KeyCode.RightArrow)) {
print("Right Pressed");
}
}


I don't feel the need to explain this code as it's pretty straight forward.
After applying this script to the player plane upon playing the game in the Unity Console (the console basically displays anything that's going on in the game window) it shows that the buttons are working.


I then modified the player script so that when the Left or Right arrow are pressed the player will rotate, when the up arrow is pressed the player moves forward and when the down arrow is pressed the player moves backwards. The new player script looks like this;

if(Input.GetKey(KeyCode.UpArrow)) {
this.transform.Translate(Vector3.forward*5*Time.deltaTime);
}i
f(Input.GetKey(KeyCode.DownArrow)) {
this.transform.Translate(-Vector3.forward*5*Time.deltaTime);
}

if(Input.GetKey(KeyCode.LeftArrow)) {
this.transform.Rotate(-Vector3.up*15*Time.deltaTime);
}i
f(Input.GetKey(KeyCode.RightArrow)) {
this.transform.Rotate(Vector3.up*15*Time.deltaTime);
}


Now before I carried on with the rest of the script I created my sprite sheet for my character, as everything is going to be 2D in my game except from the walls I can create a sprite sheet. A sprite sheet is a number of 2D Images that make a moving 2D Animation when they are played at a certain time, here is an example sprite sheet from the original gauntlet game;


Here is the sprite sheet that I created using Photoshop;


I then created a new folder in my unity project where I stored my player sprite sheet, I then applied them to the play plane changed the Shader to Transparent/Diffuse and my player was successfully entered into my game.
My game window now looks like this;

Not that much different but the player character is now in the scene.

I then tagged my character as 'player' for future use with enemies.

In the next post I will talk about how I entered enemies into my game.

No comments:

Post a Comment