- Home /
The question is answered, right answer was accepted
How do I get this 2D ball/wall bounce working?
I've got a top-down 2D scene, with X to the right, Y up, and Z (unused) into the screen.
In the scene are:
A ball object with a capsule collider with Unity's standard bouncy material and rigidbody with Z position frozen and X and Y rotation frozen and gravity off, and a script that uses rigibody.AddForce to start movement along the X axis to the right towards the wall
A wall object with a box collider and a rigidbody with gravity off
In the Physics settings, I've set the bounce threshold to 0.
What happens is the ball properly moves towards the wall but it doesn't bounce off. It collides and goes the other way, but much slower without any bounce, with the same behavior as when there's no bouncy material. It's as if the bouncy material doesn't exist. What am doing wrong?
@Fattie - thanks, but yes, there's a box collider (non-trigger) on the wall.
@Fattie - unfortunately still doesn't work. I already had the Bouncy physic material on the ball's capsule collider. I added it to the wall's box collider. No change in behavior...
@Fattie - I figured it out! What I was doing (and should have mentioned in my question) was that I had the wall frozen. So the energy from the ball was transferring to the wall, leaving little left for the ball. What works is either (1) not have a rigidbody on the wall at all or (2) make the rigidball NOT frozen but with a very high mass, so that the ball bounces off. Again, thanks for your help -- I've checked out Unity Gems and it looks excellent -- more programmer-centric than many Unity resources -- very much hope to see that site develop.
Watch this tutorial now: https://youtu.be/oqD29T7$$anonymous$$LqU
It can help you to create your required physics.
I found the solution in this video: https://youtu.be/RoZG5RARGF0
Answer by Ghopper21 · Oct 21, 2012 at 07:55 PM
I figured it out! What I was doing (and should have mentioned in my question) was that I had the wall frozen. So the energy from the ball was transferring to the wall, leaving little left for the ball. What works is either (1) not have a rigidbody on the wall at all or (2) make the rigidball NOT frozen but with a very high mass, so that the ball bounces off.
Answer by LeakySink · Oct 21, 2012 at 10:21 PM
I wouldn't set the bounce threshold to 0, that might be your issue. You could also try adding the bounciness material to the wall object.
i found the solution in this video: https://youtu.be/RoZG5RARGF0