private void ballthrow() { if (canswipe) { Xaxisforce = finaltouchposition.x - initialtouchposition.x; // force on x axis. Yaxisforce = (finaltouchposition.y - initialtouchposition.y); // force on y axis. Zaxisforce = 40 / ((finaltouchtime - initialtouchtime) + 1); if (Yaxisforce < 0) { yforce = -Mathf.Sqrt(-Yaxisforce); } else { yforce = Mathf.Sqrt(Yaxisforce); } requiredforce = new Vector3(-Xaxisforce / 4, yforce * 2.4f, -Zaxisforce); ball.GetComponent <Rigidbody>().useGravity = true; ball.GetComponent <Rigidbody>().velocity = requiredforce; canswipe = false; Invoke("reset", 7); } }
void Start() { ball = FindObjectOfType <basketball> (); initialposition = ball.transform.position; Time.timeScale = 3; // speed up the game by by 3 times. ball.GetComponent <Rigidbody>().useGravity = false; canswipe = true; }