- Home /
Makeing a sphere with rigidbody.AddTorque roll faster
I am trying to make a ball rolling game, but when i use the code below the Sphere rolls slowly.
pragma strict
var tilt : Vector3 = Vector3.zero; var jumpSpeed: float = 8; var speed : float; var fuerza = 10; private var circ : float; private var previousPosition : Vector3;
@script RequireComponent(Rigidbody) function Start() { //Find the circumference of the circle so that the circle can be rotated the appropriate amount when rolling circ = 2 Mathf.PI collider.bounds.extents.x;
previousPosition = transform.position;
}
function Update () { tilt.x = -Input.acceleration.y; tilt.z = Input.acceleration.x;
rigidbody.AddTorque (tilt * speed * Time.deltaTime);
if (Input.GetKey("up"))
rigidbody.AddTorque (Vector3(0, 0, fuerza));
if (Input.GetKey ("right")) rigidbody.AddTorque (Vector3(fuerza, 0, 0));
if (Input.GetKey ("down")) rigidbody.AddTorque (-Vector3(0, 0, fuerza));
if (Input.GetKey ("left")) rigidbody.AddTorque (-Vector3(fuerza, 0, 0));
if (Input.GetKeyDown (KeyCode.Space)){
rigidbody.velocity.y = jumpSpeed;
}
}
function LateUpdate() { var movement : Vector3 = transform.position - previousPosition;
movement = Vector3(movement.z,0, -movement.x);
transform.Rotate(movement / circ * 360, Space.World);
previousPosition = transform.position;
}
Any simple way to make the sphere roll faster? Also i cant use Rigidbody.AddForce sence I am using custom Gravity.
Answer by Chimera3D · May 07, 2012 at 03:02 AM
Yeah, I had trouble with this too. Go to Edit-> Project Settings -> Physics and Increase the max angular velocity. I don't think there is any way to make the ball roll faster in short bursts, even if you increase the max angular velocity during a getKey. :/ Also this affects all rolling objects so keep that in mind.
Note that you can override the global maxAngularVelocity by setting it on a RigidBody.
Your answer
![](https://koobas.hobune.stream/wayback/20220613071202im_/https://answers.unity.com/themes/thub/images/avi.jpg)