Need help with my script.

Hello everyone hope everything’s fine. :slight_smile:
this is my script
using UnityEngine;
using System.Collections;

public class Rigidbodyforce : MonoBehaviour {
	
	// Use this for initialization
	void Start () {
	
	}
	
	void FixedUpdate()
{
  Ray ray;
  RaycastHit hit;
  if (Input.GetMouseButton(0))
    {
        ray = Camera.main.ScreenPointToRay (Input.mousePosition);
        if (Physics.Raycast (ray, out hit))
        {
            if (hit.collider.tag == "TouchBall")
            {
                rigidbody.AddRelativeForce (0, 200, 0);
            }
        }
    }
}
}

now the problem is i want the sphere to go in random direction except the down direction it should go up in random direction.
please tell me something what should i do.
Thanks in advance. :slight_smile:

Just use a random number generator in your function.

rigidbody.AddForce(Random.Range(-500f,500f),Random.Range(0,500f),Random.Range(-500f,500f);

rigidbody.AddRelativeForce (0,Random.Range(100,300), 0);

I haven’t tested this, but it should work

200 now is going to be between 100 and 300 a number will be generated.