Now, we'll add the throw when you release the ball. First, let's add a couple of public variables to help tune the throwing behavior:
public Vector2 sensivity = new Vector2(8f, 100f); public float speed = 5f; public float resetBallAfterSeconds = 3f; private Vector3 direction;
And the Throw() function itself as follows:
void Throw(Vector2 inputPosition) { _rigidbody.constraints = RigidbodyConstraints.None; _rigidbody.useGravity = true; inputPositionDifference.y = (inputPosition.y - inputPositionPivot.y) / Screen.height * sensivity.y; inputPositionDifference.x = (inputPosition.x - inputPositionPivot.x) / Screen.width; inputPositionDifference.x = Mathf.Abs(inputPosition.x - inputPositionPivot.x) / Screen.width * sensivity.x ...