Hi,
Simply, I found this code in the forum (about control ball with rigidbody), and I started in studying it in order to learn unity:
var speed = 10.0;
var gravitypull = 0;
function FixedUpdate() {
rigidbody.AddForce (Vector3(0, gravitypull, 0));
var cameraTransform = Camera.main.transform;
// Forward vector relative to the camera along the x-z plane
var forward = cameraTransform.TransformDirection(Vector3.forward);
forward.y = 0;
forward = forward.normalized;
// Right vector relative to the camera
// Always orthogonal to the forward vector
var right = Vector3(forward.z, 0, -forward.x);
if (Input.GetKey ("w")) {
rigidbody.AddForce(forward * speed * Time.deltaTime);
}
if (Input.GetKey("s")) {
rigidbody.AddForce(forward * -speed * Time.deltaTime);
}
if (Input.GetKey ("d")) {
rigidbody.AddForce(right * speed * Time.deltaTime);
}
if (Input.GetKey ("a")) {
rigidbody.AddForce(right * -speed * Time.deltaTime);
}
}
I understand most of the code, but the following part I do not understand how important, and what is the relationship move the ball with the camera:
var cameraTransform = Camera.main.transform;
// Forward vector relative to the camera along the x-z plane
var forward = cameraTransform.TransformDirection(Vector3.forward);
forward.y = 0;
forward = forward.normalized;
// Right vector relative to the camera
// Always orthogonal to the forward vector
var right = Vector3(forward.z, 0, -forward.x);