I’m trying to make a simple ball game where the player has to keep tapping or clicking on a ball to avoid it hitting the ground. I’ve got it so the ball goes up when clicked but I want it to go up when clicked more like a ball would go up in real life rather than in a straight line up so the player can’t just keep clicking in same place to keep scoring.
This is my script so far
public class Ball : MonoBehaviour
{
public Rigidbody RB;
private float maxTorque = 10;
private float zBounds = 0;
private float xBounds = 7;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(transform.position.z < zBounds)
{
transform.position = new Vector3(transform.position.x, transform.position.y, zBounds);
}
if (transform.position.x < -xBounds)
{
transform.position = new Vector3(-xBounds, transform.position.y, transform.position.z);
}
if (transform.position.x > xBounds)
{
transform.position = new Vector3(xBounds, transform.position.y, transform.position.z);
}
}
private void OnMouseDown()
{
RB.AddForce(Vector3.up * 10, ForceMode.Impulse);
RB.AddTorque(Random.Range(-maxTorque, maxTorque), Random.Range(-maxTorque, maxTorque), 0, ForceMode.Impulse);
}
}