how can i rotate the ball in left direction deirection if it was in forward direction and vice versa , like a real ball?

if (Input.GetMouseButtonDown(0) && !isDead)
{
isPlaying = true;

        score++;
        scoreText.text = score.ToString();
        if (dir==Vector3.forward)
        {
            dir = Vector3.left;
        }
        else
        {
            dir = Vector3.forward;
        }
    }
   
    float amountToMove = speed * Time.deltaTime;

    transform.Translate(dir * amountToMove);
}

Hi @hamzachaudhry

You could use this.

void Update ()
 {
		transform.Rotate(Vector3.forward * Time.deltaTime*50);
}

You can change Vector3.forward to Vector3.left, Vector3.down etc.
Also to avoid calling this code all the time (since it is in update), you could use a boolean

bool canRevolve = false;
 void Update ()
     {
               if(canRevolve)
    		transform.Rotate(Vector3.forward * Time.deltaTime*50);
    }

Activate and Deactivate boolean necessarily.
Hope this will help.
Happy Coding…

Rajeesh is right, but that will constantly make it move in just one direction while the boolean is true. If moving to the right makes the boolean true, than it will still rotate forward instead of right. The solution to this is binding rotation AND movement to an axis. For example:

var speed : float = 5;

function Update  () {
 
var forwardMovement = Input.GetAxis ("Vertical") * speed;
var horizontalMovement = Input.GetAxis ("Horizontal") * speed * Time.deltaTime;
 
transform.Rotate(forwardMovement, 0, horizontalMovement);
transform.Translate(horizontalMovement, 0, forwardMovement);
}

I’m not positive, but due to the nature of rigidbodies and AddRelativeForce/AddForce, you might be able to invoke both movement and rotation using either of those, since force affects both rotation and position instead of just position. But I’m not 100% sure it will work.

Example code for this might be:

var speed:  float = 5;

function Update  () {
 
var forwardMovement = Input.GetAxis ("Vertical") * speed;
var horizontalMovement = Input.GetAxis ("Horizontal") * speed;

rigidbody.AddRelativeForce (horizontalMovement, 0, forwardMovement);
}

I can’t test (and won’t be able to for a while) any of these, so if someone can test out both ideas for me, that would be great.

Hope this helps!