Moving Cube Forward

Hi,

What I have done so far is made a C# Script called player (player being the cube object) and coded it in the following way:

using UnityEngine; using System.Collections;

public class Player : MonoBehaviour {

public float PlayerSpeed;
void Start()
{
}
// Update is called once per frame
void Update () 
{
    // Amount to Move
    float MoveHorizontal = Input.GetAxis("Horizontal") * PlayerSpeed * Time.deltaTime;
    float MoveVertical = Input.GetAxis("Vertical") * PlayerSpeed * Time.deltaTime;

    // Move the Player
    transform.Translate(Vector3.right * MoveHorizontal);
    transform.Rotate(0, PlayerSpeed * MoveVertical, 0);

}

With the code above, hopefully you will see that I did get the cube (Player) moving about the x and y-axis'.

I have visited the Input Manager under Edit->Project Options->Input and made it so I can have the keys that I wanted, for the movement about the vertical and horizontal axis.

I'm wondering now that if their is a z-axis that I am missing under the Input Manager? I have checked around on the net and it seems that what some people are doing is just rotating the position in some way to move forward..

But, so far so good.

This is the solution, however, RotateSpeed needs to be tweaked a little, e.g. faster.

using UnityEngine; using System.Collections;

public class Player : MonoBehaviour {

public float MoveSpeed = 10;
public float RotateSpeed = 40;

void Start()
{
}
// Update is called once per frame

void Update () 
{
    // Amount to Move
    float MoveForward = Input.GetAxis("Vertical")  * MoveSpeed * Time.deltaTime;
    float MoveRotate = Input.GetAxis("Horizontal") * RotateSpeed * Time.deltaTime;

    // Move the player
    transform.Translate(Vector3.forward * MoveForward);
    transform.Rotate(Vector3.up * MoveRotate);

}

}

You can add any number of axes in the input manager and do whatever you like with them, including making a z-axis control.

Okay, I work with JavaScript and no nothing about C# so I do not know if this only applies to JavaScript, but the way I do it is this:

if(Input.GetButton("W")) { transform.position = transform.forward * PlayerSpeed * Time.deltaTime }

This would make the GameObject move forward when the W key is pressed, as in a WASD control scheme. However, like I said, if this is only JavaScript stuff I heartily apologize to you :)