Speed limit?

I’m creating a basic game for a college course and I’m having trouble with the controller script.

I have the script set to rotate a ball so you move around the level by rolling, I have the movement and rotation limited to set axis so it only moves along a 2D plane and doesn’t rotate vertically to the camera view. (Z position is frozen, X and Y rotation are frozen)

I seem to be hitting a speed limit though, I can’t get it to go faster than 3.5 according to the gui script I’m using to show me the speed.

Here’s the GUI script and controller script.

function OnGUI()
{ 
  GUI.Label(Rect(0,0,100,100), rigidbody.velocity.magnitude.ToString());
}

function Update () {
if (Input.GetKey ("right")) {
rigidbody.AddRelativeTorque (Vector3.back * 200);
}
if (Input.GetKey ("left")) {
rigidbody.AddRelativeTorque (Vector3.forward * 200);
}
}

If I had to guess, you might be hitting Rigidbody.maxAngularVelocity. Looks like you can change that value, although I don’t know how far you can push it before running into problems.

You might try attacking this from another angle.

First, let’s assume that PhysX is calculating your ball’s movement based on more or less realistic circular kinematics:

v := rω; //linear velocity equals radius times angular velocity
a := rα; //linear acceleration equals radius times angular acceleration

Given the script reference’s reported max angular velocity of 7, this implies that your ball’s maximum velocity is seven times its radius. Since you’re peaking at 3.5, that seems to indicate you’re using a ball with radius 0.5? If so, this guesswork might have some merit.

If all of that is true, then you have two ways to increase your effective speed limit:

  • Increase the ball’s max angular velocity
  • Increase the ball’s radius

The first option is probably a quick change, so I’d try that first.

The second option might require that you rescale any levels or assets you’ve already created, but it’s good to know that you probably have a fallback method.

your if statements need moved to a fixedUpdate function
i tried to post the page i found the answer at but not sure how the page is in scripting manual.