I've already set the ball (my object) initially at the start where I have to click for the ball to launch from the paddle (it's a ping pong game).
private void LockBallToPaddle() {
Vector2 paddlePos = new Vector2(Paddle.transform.position.x,
Paddle.transform.position.y);
transform.position = paddlePos + paddleToBall; //For the ball to stick to the paddle
}
Launch the Ball:
private void LaunchBall() {
if (Input.GetMouseButtonDown(0)) {
hasStarted = true;
rbBall.velocity = new Vector2(Random.Range(-2f, 2f),speedVelocity);
}
}
Both of which I put under Update()
private void LaunchBall() {
if (Input.GetMouseButtonDown(0)) {
hasStarted = true;
rbBall.velocity = new Vector2(Random.Range(-2f, 2f),speedVelocity);
}
}
Now the problem is when my ball hits a certain collider, I want it to respawn the position back to the paddle. So instead of Destroy the game object, I just copy and paste those same methods under collision
if (collision.gameObject.tag == "bottom") {
LockBallToPaddle();
LaunchBalls();
}
But now it just launches straight away from the paddle when hit the collision without me clicking anything like what "Launchballs()" intended to. What should I do?