First off here is the code for side to side:
pragma strict
var health : int = 100;
var speed : int = 400;
function Start () {
}
function Update () {
if(Input.GetAxis("Horizontal")){
transform.Translate(Vector3(Input.GetAxis("Horizontal") * speed * Time.deltaTime, 0, 0));
}
}
What I want to add is my player being able to move up and down on the Y axis. I have done things like this:
pragma strict
var health : int = 100;
var speed : int = 400;
function Start () {
}
function Update () {
if(Input.GetAxis("Horizontal")){
transform.Translate(Vector3(Input.GetAxis("Horizontal") * speed * Time.deltaTime, 0, 0));
}
if(Input.GetAxis("Vertical")){
transform.Translate(Vector3(Input.GetAxis("Vertical") * speed * Time.deltaTime, 0, 0));
}
}
But then it just makes it so when I press W to go up it just moves left, and when I press S to go down it just makes me go right. Then when I try to go side to side on the X axis using A and D it does nothing. The camera angle is like PacMan, so the camera is directly above the seen looking down on the terrain. I used Javacode for the scripts and my main character was built off of a cube.
It is a 2D game.