Before you get the player moving, you'll need to attach a script to the player capsule:
- Create a new C# script in the Scripts folder, name it PlayerBehavior, and drag it into the Player capsule.
- Add the following code and save:
public class PlayerBehavior : MonoBehaviour
{
// 1
public float moveSpeed = 10f;
public float rotateSpeed = 75f;
// 2
private float vInput;
private float hInput;
void Update()
{
// 3
vInput = Input.GetAxis("Vertical") * moveSpeed;
// 4
hInput = Input.GetAxis("Horizontal") * rotateSpeed;
// 5
this.transform.Translate(Vector3.forward * vInput *
Time.deltaTime);
// 6
this.transform.Rotate(Vector3.up * hInput * Time.deltaTime);
}
}
Using the this keyword is optional. Visual Studio 2019 may suggest that you remove it to simplify the code, but I prefer leaving it in for clarity.
When...