- Home /
How do I use rigidbody's collision detection modes?
So, I'm yet another guy trying to make a breakout game. And I have problems implementing the ball's movement physics.
After trying Unity's built-in physics (the result was not very pleasant) I came up with conclusion that since the mechanics are pretty simple all I need is the collision detection and info - not the reaction. So I added rigids to all my objects, made ball and paddle kinematic, added the OnCollisionEnter code to ball's script where I reflect his velocity on hit. The problem is that sometimes the ball still acts weird. It could move through a wall or a brick causing it get out of the gaming area or destroy the bricks it should not normally reach.
I read Unity's documentation on rigidbody's Collision Detection Mode and it looks like I should use the Continuous Dynamic mode. But I don't quite understand how do I use it. Should I just set it to Cont. Dynamic for moving objects (ball, paddle) and Discrete for static (wall, brick) and how IsKinematic would influence it?
Right now the ball has Continuous Dynamic mode, IsKinematic checked, so does the paddle, walls and bricks are Discrete and still sometimes ball can go through any of this objects. I am confused.
$$anonymous$$ost people facing the issue of objects moving through are helped more by reducing the fixed timestep:
Edit > Project Settings > Time
Try reducing 'Fixed timestep' from 0.02 to 0.01 to start.
Answer by pekrewrek · Feb 13, 2014 at 03:23 PM
Sorry - forgot to post back. But better late then never, right? :) Thenks, robertbu. Making smaller timestep helped resolve the issue with ball going through some of the colliders.
Answer by terresquall · Jun 21, 2020 at 07:07 AM
This question is old! But to answer your question, if you want your objects (e.g. ball, paddle) to always block fast moving objects from tunnelling through, you have to set them as Continuous. Discrete objects are not always guaranteed to block objects that are continuous. Here's an article here with more detailed explanation: https://blog.terresquall.com/2019/12/collision-detection-modes-in-unitys-rigidbody-component/