# Objects stick together on Collision

I have a ball which has CircleCollider2D attached to it. It is also rigidbody. When it lands on a platform, it jumps . The platform is static, with Edge Collider attached. It also has a platform effector attached with "Use One Way" selected.

Most of the times it works fine, but some times, the ball lands on the platform and instead of bouncing, just sits on the platform.

When ball lands on the platform, following code is executed:

 rb.AddForce(upForce, ForceMode2D.Impulse);


upForce is Vector2(4,10);

image shown below:

Why is this happening?

• Where are you calling the addforce method? Is it in OnCollisionEnter2D... If so,try changing it to OnCollisionStay2D. – Savlon Aug 16 '15 at 15:39
• Nice catch. It occurs once in may be 200 attempts. Very difficult to reproduce. But OnCollisionStay2D will certainly take care of it. No way of validating, but it should – SanSolo Aug 16 '15 at 18:03
• @Savlon please write it as answer. – SanSolo Aug 17 '15 at 6:42

As requested by SanSolo - Comment converted to answer.

If you are calling the AddForce method from OnCollisionEnter2D then it will only get called on the initial contact of both colliders. If for some reason, your collision fails to get recognised, your AddForce method will fail.

An easy way to fix this is to simply place your AddForce method inside of the OnCollisionStay2D method. This will ensure that your AddForce method gets called every time your colliders are in contact regardless of any unrecognised initial collisions.

Gravity in unity is a default of roughly 9. Are you simulating gravity, are you using the correct scale and have you tried adding more force?

• He doesn't need gravity its rigidbody – Vadim Tatarnikov Aug 17 '15 at 7:15
• Not my point. His force is only +10. As gravity is -9 I thought it may just not be enough force to move it – cfehunter Aug 17 '15 at 7:17
• Oh yes that makes sense sorry – Vadim Tatarnikov Aug 17 '15 at 7:20

Try using AddForce() in the function OnCollisionStay2D() so that it is called every time there is a collision.