Resetting the ball to the paddle

BlockBreaker.zip (9.1 MB)

Can you look at it please? It’s almost 4am and i am not going to sleep cause of this :smiley: I’ve almost done this at the start only needed to STOP the damn ball. Meh

PS I know the game’s theme is pretty weird.

Just extracting it now… give me a few moments…


Updated Sun May 27 2018 02:42

In the Ball.cs script, your Update method is allowing the paddle to be moved separately to the ball, and at the very beginning the slight movement of the paddle hits the ball and causes a collision, invoking your tweak to be applied to the ball. After this, the ball has a larger Y value and will make increasingly larger rebounds on the paddle due to gravity. At no point is GameStarted set to true during this, so you are still then able to apply the velocity with the mouse button press. To correct this;

void Update()
{
	if (!GameStarted)
	{
		// lock the ball relative to the paddle
		this.transform.position = paddle.transform.position + paddleToBallVector;

		if (Input.GetMouseButtonDown(0))
		{
			GameStarted = true;
			this.GetComponent<Rigidbody2D>().velocity = new Vector2(Random.Range(-2f, 2f), 12f);
		}
	}
}

Additionally, you still have a mistake in Reset method which, when called, places the ball in the wrong location, to correct this;

public void Reset()
{
    GameStarted = false;
    ImmediateStop();
    this.transform.position = new Vector2(paddle.transform.position.x, 0.82f);
    paddleToBallVector = this.transform.position - paddle.transform.position;
}

Hope this helps :slight_smile:

1 Like

It did :f I am miserable. Thank you very much Rob :slight_smile:

You’re very welcome, hopefully you’ll be happy again tomorrow and will continue to make great progress on your game :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms