public void kickMe(Vector2 tappos) { Rigidbody2D rb2 = Ball.GetInstance().gameObject.GetComponent <Rigidbody2D>(); //ignore if ball travelling upwards if (rb2.velocity.y >= 0) { return; } //tap too far // Debug.Log ("rb2 position: "+rb2.position); // Debug.Log ("distance bwtn tap and rb2: "+Lib.pythag(tappos,rb2.position)); if (Lib.pythag(tappos, rb2.position) >= 0.8f * tapTolerance) { return; } float dx = -(tappos.x - rb2.position.x) * 100f; rb2.AddForce(new Vector2(dx * xForceDirection, yForceDirection * 1f)); screen_game game = screen_game.GetInstance(); game.doCollision(tappos); var score = game.increaseScore(1); //if (score % 10 == 0 && xForceDirection <= 5) //{ // xForceDirection ++; //} playSound(kick); }
public void kickMe(Vector2 tappos) { Rigidbody2D rb2 = Ball.GetInstance().gameObject.GetComponent <Rigidbody2D>(); //ignore if ball travelling upwards if (rb2.velocity.y >= 0) { return; } //tap too far if (Lib.pythag(tappos, rb2.position) >= 0.8f) { return; } float dx = -(tappos.x - rb2.position.x) * 500f; rb2.AddForce(new Vector2(dx, 1500f)); screen_game game = screen_game.GetInstance(); game.doCollision(tappos); game.increaseScore(1); playSound(kick); }