Heading towards 'Game Over' after few seconds

Hi there and hello everyone.

Recently started this course and I’m amazed so far so good.

I’ve got problems narrowing down the time when my error first came up, but it must be around this part of the course.

So here’s my problem:

When I hit ‘"play’ after a few seconds I am confronted with the ‘Game Over’ scene.

That only occurs when I don’t launch the ball.

So I’m wondering if anybody else got this problem and maybe, maybe also got a solution to this strange behaviour.

Cheers
Keep on codin’

The only thing that comes to mind on this is to check your lose collider is not misplaced and clipping the ball slightly.
This would be consistant with it not detecting playing the game as it may not be in the collision area for long enough for it to be detected.

There may be a code issue but that would be my first port of call

Hi Daniel,

Try to add the following to your Ball.cs:

void Start ()
{
    paddleToBallVector = transform.position - paddle1.transform.position;
    myAudioSource = GetComponent<AudioSource>();
    myRigidBody2D = GetComponent<Rigidbody2D>();
    myRigidBody2D.simulated = false; // <-------- add this
}
	
private void LaunchOnMouseClick()
{
    if (Input.GetMouseButtonDown(0))
    {
        hasStarted = true;
        myRigidBody2D.velocity = new Vector2(xPush, yPush);
        myRigidBody2D.simulated = true; // <-------- add this
    }
}

Does that fix the issue?

Hi Nina & irresistiblejelly,

thanks for the quick support.

Nina’s hint dit it. I had to set simulated to false and then to true to work it out, but no it is working fine.

Both of you thank you very much :slight_smile:

1 Like

I’m glad it helped.

Rick sets the Collision Detection of the Rigidbody2D to “Continuous” in one of the next videos. That fixes the issue, too. Since “Continuous” takes up more CPU time than “Discrete”, you could keep the code instead if you want.


See also:

1 Like

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

Privacy & Terms