Rolling ball camera?

hi, im trying to make a rolling ball game, the ball moves with respect to the axis of the world (xyz) I want the ball moves forward when the camera rotates

this is the ball script

var fuerza = 10;

function Update () {

if (Input.GetKey("up"))
    rigidbody.AddForce(Vector3(0, 0, fuerza));

if (Input.GetKey ("right"))
    rigidbody.AddForce(Vector3(fuerza, 0, 0));

if (Input.GetKey ("down"))
    rigidbody.AddForce(-Vector3(0, 0, fuerza));

if (Input.GetKey ("left"))
    rigidbody.AddForce(-Vector3(fuerza, 0, 0));

}

Just for a point of reference, when the class isn't derived from <i>MonoBehaviour</i>, it's not necessary for the class and script (*.cs file) to have the same name.

Nope. That was the only error that popped up

1 Answer

1

I to have been playing with a rolling ball idea for some time, here's a vbery simple solution.

child an empty game objject to the ball, make sure its in the centre, then add this code:

function Update () {
    transform.eulerAngles = Vector3(0, 0, 0);
}

to the camera, and make the camera the child to empty game object.

Should work untill you find a more complex solution