hi, I know how to move static objects, with transforms. but how can I move ball with physics. I mean I click forward button[w] and ball rolls forward following terrain. when I click jump[space] it jumps. also can I make ball bounce up and down all the time? I got this effect while messing with physics components and kind of liked it. (very relaxing to watch xD)
To make the ball bounce all the time set its physics material bounciness to 1 and the bounce combine to maximum. To "steer" the ball with physics you will need to either apply forces to its rigidbody or set its velocity directly. Both can be done with member functions of the rigidbody component, which you can look up in the scripting reference.
You'll probably want to apply torque to rotate the ball. Then its friction with the surface it is on will convert that into motion. This works when applied to a sphere:
function FixedUpdate() {
var torque = Vector3(Input.GetAxis("Vertical"), 0, -Input.GetAxis("Horizontal"));
torque = Camera.main.transform.TransformDirection(torque);
torque.y = 0;
rigidbody.AddTorque(torque.normalized*speed);
}
If you instead apply the force directly to the ball, it might seem to work similarly, because the friction with the contact surface will cause it to roll (the inverse of the above). However, on, say, ice, it will accelerate faster (and not roll much). Of course, that might be what your game requires.