I tried sticking the ball to the paddle and the game instantly ends and goes to the lose screen. So i put a small gap between the ball and paddle and that fixed the game ending problem, but once i launch the ball up and it comes back down, the game ends as soon as the ball hits the paddle and its like the ball goes through the paddle when it comes back down. Any idea what code be causing this to happen? my code is exactly the same as the instructor and i turned on “continuous” by the collision detection by the ball and the paddle but i still get the same problem. Also i added a “Debug.Log(gameObject.name+” has been hit by “+collision.gameObject.name);” to my LoseCollider script to find out what is triggering the collision to end the game and its said in the console “Ball has been hit by Paddle”. Please Help!
It sounds like you have the LoseCollider script attached to Ball. This should be on the collider game object which sits just below the game space.
Thanks for the help Martyn.
I removed the LoseCollider script from the Ball but now, once the ball falls down to the bottom of the screen to the actual LoseCollider, the game doesn’t end? How do i fix this?
There should be a collider which you added just out side of the play space at the bottom, e.g. below the paddle. The LoseCollider script should be added to this, then, when the ball misses the paddle and falls to the bottom, it hits the collider and triggers the end of the game/loss of life etc.
Check out Section 5, Lecture 73.
Hi, Rob.
Thanks for the reply.
i found the problem. i had the Lose Collider and LoseCollider script in my scene already. the problem was that the “is trigger” box was ticked in the Lose Collider and unticking it made the code work.
Thanks you so much for the help
Hi,
Can you;
- check to see if you have Is Trigger enabled on the BoxCollider2D component on the LoseCollider GameObject, if not, enable it and re-test.
If it is already enabled;
- please copy/paste your code from the LoseCollider.cs and LevelManager.cs scripts into your reply, and apply code formatting (makes it easier for us to read).
Thanks.
See also;
- Forum User Guides : How to apply code formatting within your post
Hi, Rob.
Thanks for the reply.
i found the problem. i had the Lose Collider and LoseCollider script in my scene already. the problem was that the “is trigger” box was ticked in the Lose Collider and unticking it made the code work.
Thanks you so much for the help
hmmm, interesting…
You probably have/had the opposite method checking for the collision in your code then, e.g. OnTriggerEnter2D
or OnCollisionEnter2D
.
With the Is Trigger enabled on the LoseCollider’s BoxCollider you would need to use the OnTriggerEnter2D
method for detecting the collision, if you don’t have this enabled, then you would need to use the OnCollisionEnter2D
.
The former will allow the ball to travel through the LoseCollider, the latter would have the ball stop on the collider (and potentially bounce).
It would probably be worth you just running through the Hierarchy/Inspector and checking all of your GameObjects for any duplications of scripts and so on before proceding, just to reassure yourself all is well with the project and to potentially remove any obfuscation of future issues
Glad you can move forward again
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.