Roll a Ball - Beginner Scripting Question
Hi, I was working on the Roll a Ball tutorial, and I had a question about the PlayerController script that was written. How is it that Unity knows that if I press the forward arrow key or the "w" button the object knows to move in the forward direction? From the script (which I attached below), I understand that:
1) the float variables record the vertical and horizontal location of the object.
2) object is given new vector components and force is added through the rigidbody.
There is no reference to the directions (such as the forward arrow key applying force in the z direction).
If my post does not make too much sense, please let me know. I am very new to C# scripting (and scripting in general). If someone could direct me in the right direction or explain the problem, I would really appreciate it.
Thank you.
public class PlayerController : MonoBehaviour {
public Rigidbody rb;
public int speed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
}