how to make a ball roll left and right in unity code example
Example: how to make a ball roll left and right in unity
void FixedUpdate () {
float hor = Input.GetAxis("Horizontal");
float ver = Input.GetAxis("Vertical");
if (Mathf.Abs(hor) > deadZone) {
rigidbody.AddTorque(Vector3.up * turnSpeed * Input.GetAxis("Horizontal"));
}
float yRot = transform.rotation.eulerAngles.y;
Vector3 newForward = Quaternion.AngleAxis(yRot, Vector3.up) * Vector3.forward.normalized;
if (Mathf.Abs(ver) > deadZone) {
rigidbody.AddTorque(newForward * forwardSpeed * Input.GetAxis("Vertical") * -1);
}
}