Why does the ball stick to the newly created walls?

So there must be an easy fix but I have created all the BoxColliders2D as walls and changed the gravity settings globally via the Edit > Project Settings but the ball just launches and sticks to the newly created walls?

I have gone through the video several times and checked all settings and they are identical (until you point our something I missed?). Can anyone help?

1 Like

Hi Lloyd,

Any chance of a video showing the behaviour?

Sorry about the delay (I’n not at work I swear). This should show the behavior and settings I am experiencing.

Hi Lloyd,

Thanks for sharing the video clip.

At the moment,

  • you don’t have any gravity as it’s value is set to zero
  • you don’t have a Physic Material 2D on the Circle Collider 2D component of the Ball GameObject

Without gravity, your ball is not going to fall back towards the bottom of the screen unless there is a force pushing it in that direction. Without the Physic Material 2D, you have no bounce, which would be the force moving the ball.

Lecture 50 covers the Physics Material, I note that you have a Materials folder. If you do have the Bounce material, apply it to the Material property of the Circle Collider 2D component on the Ball GameObject and this will resolve the issue for you.

Hope this helps :slight_smile:


See also;

1 Like

Tested and this fixed this issue. I also have my “Bounce” material attached to the paddle polygon collider. I have since played around with the materials and understand where i slipped up. Thanks again!

1 Like

Hi Lloyd,

Aha, so perhaps just a case of assigning the material to the wrong GameObject then. I’m glad you can move forward with the course again, and, of course, you are very welcome :slight_smile:

Hi Rob,
I’m having a similar issue, but I noticed it on;y “sticks” to the top wall, and bounces off the side walls. I set my material to “bouncy” as suggested, but it bounces down for a second and then travels back up, jittering at the top of my screen. Does it have to do with the force applied by the “launch ball” code that is applying a constant force, perhaps?

1 Like

Nevermind, I see the issue. I forgot my curly braces after my if statements:

if (!hasStarted)
            lockToPaddle();
            launchBall();

 if (Input.GetMouseButtonDown(0))
            hasStarted = true;
            GetComponent<Rigidbody2D>().velocity = new Vector2(launchX, launchY);
1 Like

Hi Tamarack,

I’m glad you managed to resolve the issue yourself, well done.

Regarding the curly braces, if you don’t include them to form a block, only the next single line of code will be included as part of the if statement logic (in this case).

Personally, I always include them, even if I was only going to have one statement anyway, I find if I am consistent in my approach I tend to make less mistake… of course, I could just make mistakes consistently… hehe :wink:

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

Privacy & Terms