Movement Problems

Whenever I change direction, the ball I am controlling goes out of control and starts moving in the wrong

Here is the code I use to move:

#pragma strict


var rotationSpeed = 280;
var jumpHeight = 8;
var distToGround : float;


var hitOne : AudioClip;
var hitTwo : AudioClip;
var hitThree : AudioClip;




function Start () 
{
    //Getting the distance from the center of the ball to the ground.
    distToGround = collider.bounds.extents.y;
}


function Update () 
{
    //Handles ball rotation to move.
    var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
    rotation*= Time.deltaTime;
    rigidbody.AddRelativeTorque (Vector3.back * rotation);
    
    if(Input.GetKeyDown(KeyCode.W)  IsGrounded ())
    {
        rigidbody.velocity.y = jumpHeight;
    }
}


function IsGrounded () : boolean
{
    return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1);
}


function OnCollisionEnter () 
{
    var theHit = Random.Range(0, 3);
    if (theHit == 0) 
    {
        audio.clip = hitOne;
    }
    else if (theHit == 1)
    {
        audio.clip = hitTwo;
    }
    else
    {
        audio.clip = hitThree;
    }
    audio.pitch = Random.Range(0.9, 1.4);
    audio.Play();
}

This is pretty much breaking the game because it makes it near-impossible to move past the second level.

Is it possible you should be using rigidbody.AddTorque() instead of AddRelativeTorque? It’s not clear what coordinate system you intend to use to control movement, or what creates that movement. The torque you add acting against the ground is what drives the ball to change position? Take care to describe your situation - a full description of the problem scenario, what it is doing, and what you want it to do. Then folks are more likely to be able to help.

Hold on, I’ll post a link to the game. Everything in the first level is fine (apart from the disgusting placeholder textures) but in the second level, it is impossible to proceed past the slope (and the horrendous placeholder textures).

https://dl.dropboxusercontent.com/u/269065796/Paper%20Ball.html Second level and up the slope. I’ve moved the start up there to test it out and it works. It is just the turning around part.

Sorry, this web player doesn’t seem to load for me.

Same. Any idea how to use it? I have both files in the Dropbox.

They must be in the same location. Any chance you did your build without adding the scene?

No chance. One of the main scripts requires all of the scenes to be in the build list, and I got that code working perfectly this morning.