The ball keeps locking to the paddle when I launch it, I put in the bool exactly like Rick but somehow it’s just not working for me D:
{
[SerializeField] Paddle paddle1;
//state
Vector2 paddleToBallVector;
bool hasStarted = false;
// Start is called before the first frame update
void Start()
{
paddleToBallVector = transform.position - paddle1.transform.position;
}
// Update is called once per frame
void Update()
{
if (!hasStarted)
{
LockBallToPaddle();
LaunchOnClick();
}
}
private void LaunchOnClick()
{
if (Input.GetMouseButtonDown(0))
{
hasStarted = true;
GetComponent<Rigidbody2D>().velocity = new Vector2(2f, 15f);
}
}
private void LockBallToPaddle()
{
Vector2 paddlePos = new Vector2(paddle1.transform.position.x, paddle1.transform.position.y);
transform.position = paddlePos + paddleToBallVector;
}
}