Problem with Unity2D Ball Physics

Hello guys,

I’m creating a 2D volleyball game and I ran into a problem with the physics behavior of the volleyball.

I want the ball to be accelerated by using the AddForce() method on collision, while ignoring the acceleration happening from the two rigidbodies colliding. (the ball gets too fast from the collision)
Also gravity should be applied to the ball, and the player should not get knocked back when the two collide. (I achieved this by increasing the player’s mass)

Can i somehow achieve this while still using the implemented Unity2D physics?
Right now I’m handling it with applying a force in the direction of the contact point normal:

rigidbody.AddForce(collision.GetContact(0).normal * playerBounce, ForceMode2D.Impulse);

but the change in acceleration applied by the collision of the rigidbodies is interfering.

If anyone has an idea how to do this without changing the ball body type to Kinematic it would be very helpful. :slight_smile:
Because then I would have to write custom gravity and force applying code, right? (don’t want that xD)

I also tried to do this by using Trigger type colliders, the problem with those was that I need the ability to read the relativeVelocity of the collision.

Thank you very much in advance for your help! :slight_smile:

Thank you for your answer.

I’ve actually tried this in the meanwhile, but I ran into some problems:

When the ball hits the player (via isTrigger collider), the balls velocity is changed so that it flies in the direction of the hit.

Sometimes though, it seems that the ball is travelling too far. (inside the player’s collider or into a wall)

I tried fixing this by using custom collision detection inside FixedUpdate(), but Physics2D.OverlapCircle() as well as Collider2D.Cast() resulted in the same laggy/too slow collision detection.

Has anyone an idea how to improve/fasten the collision detection so that the objects don’t travel into each other?

The Rigidbodies have continuous collision detection enabled, the ball’s RB is kinematic and the player’s is dynamic.

They both have it on an i tried it with a time step of 0.005 and it still didn’t improve. Maybe it’s because the player’s Rigidbody is dynamic and affected by gravity?
At least it didn’t improve with using Physics2D.OverlapCircle() or Collider2D.Cast()

So, before decreasing the time step value, I used OnTriggerEnter2D, but it was too slow. (colliders travelling into each other)

To fix this I tried checking collisions in FixedUpdate() with Physics2D.OverlapCircle(), but it was exactly the same.

Finally I decreased the time step value to 0.005, but the lag still didn’t improve.

Next thing I could try is using both OnTriggerEnter2D and time step of 0.005
I will try this out later.