# Collision Detection: Discrete vs. Continuous vs. Continuous Dynamic

Discussion in 'Physics' started by jashan, Jan 18, 2015.

1. ### jashan

Joined:
Mar 9, 2007
Posts:
3,307
I'm a little puzzled by the documentation. For Continuous, it says:
Why only static MeshColliders? What about the others, like a BoxCollider for instance?

For Continuous Dynamic it says:
... so, again, no word on non-MeshColliders. A little later it says:

... so ... is Continuous on a Rigidbody with a BoxCollider that should collide with other BoxColliders enough? Or do I need Continuous Dynamic?

ElnuDev, neonblitzer, JoshW_3 and 2 others like this.
2. ### Nanako

Joined:
Sep 24, 2014
Posts:
1,047
bump because i want an answer to this, too

Joined:
Aug 8, 2013
Posts:
4
From my testing what I can tell here is this (and I've verified in a demo scene)
Let's take several cases.
1. A projectile (discrete) travelling fast will go through a static wall (simply a box collider OR a mesh collider. Its not a dynamic object as there's no rigidbody.
To solve, we add continuous to the projectile - voila. Problem solved, no matter the speed.

Now let's take it a step further and add a dynamic object to the mix. In front of our static (ie no rigidbody, dont actually have to mark as static in 5.x) wall that our projectile hits we dangle a sphere on some hinge joints (we could prob also just drop a sphere there and on its rigidbody turn off gravity - but the dangling ball looks cooler)

Even though our projectile is set to continuous, it will go right through the dangling ball. We must set the dangling ball OR the projectile to continuous dynamic. Both have to be at least continuous and one continuous dynamic. The mesh collider here doesn't matter.

Bottom line - it works as I've described with mesh colliders or a box collider. My guess mesh colliders are mentioned as they are the most complex type of collider, but from what I can see this applies to all colliders (3d - haven't done any 2d testing here)

4. ### jason_nyan

Joined:
Apr 18, 2017
Posts:
1

I would like to add on to what actually happens behind the different settings:

The same principle applies to all dimensions. (2D/3D)
Suppose you have an object travelling at a certain speed v in a frame, lets t=1 represent the interpolant value of the distance moved, | | is the volume of the wall, and p intersects the wall | | at some point where t=0.8.
p' = p + vt

Scenario: Fast moving object or big time-step between frames
(Edit: sorry for the _ as "spaces", multiple spaces doesn't display properly)

_____________v-------------------------->
Discrete:______p__________| |____p'
Result: No collision detected, physics checked p' against wall | | and found no intersection. This is a common problem when you check small bounding volume against another thin/small bounding volume.

_____________v-------------------------->
_________________________vi----->
_____________________<-----vr
Continuous:____p______p''___| |___p'
Result: Physics did a calculation considering at which t-value p intersects with other colliders before reaching p', and found that at t=0.8, p touches | |, so it returns a response of vr, resulting in final position p''.

Continuous Dynamic: This is really just some kind of bit-masking used to sort/process physics object that should or should not react with one another. If you expect your object to react to other dynamic stuffs(moving stuffs with rigidbody & colliders), use "dynamic" whenever possible for best result (But remember to watch the performance & remove whenever possible).

5. ### laurentlavigne

Joined:
Aug 16, 2012
Posts:
6,473
I'll translate to english The CD rigid will use discrete with discrete rigids and continuous with continuous rigids CDs and statics. It's the best of both worlds and the overhead isn't too bad.

The reasons why it doesn't exist in 2D physics is because continuous behaves like CD.

My experience with fast moving projectile is that discrete is better if you do both trigger and collider (for example a 2 damage boulder that pierce through a 1 HP enemy and bounces off a 3HP enemy). It seems trigger gets called after collide in continuous, in 2D at least. If you want to avoid passing through, use a traveling raycast or if you like giving your cpu a hard time, stretch the collider in the direction of travel.

Correction: use CD it's awesome, I was having problem with trigger because I assumed Stay happens on Enter as well but in fact OnTriggerStay happens on the next tick (or is that frame) so I needed to take into account 1HP enemy inside OnTriggerEnter and voila

Last edited: Jun 18, 2017
6. ### BrandyStarbrite

Joined:
Aug 4, 2013
Posts:
2,077
Wow! This info was interesting.

QuickBehindYou and calebmantey like this.

### Unity Technologies

Joined:
Jul 24, 2013
Posts:
597
I think the intended behaviour here was to compute continuous contacts with just static colliders in Continuous mode, and to compute continuous contacts with anything in the Continuous Dynamic mode.

Example:

1) If you want to hit a wall with a bullet -- use Continuous (typical case)
2) if you want to hit another bullet with a bullet -- use Continuous Dynamic.

Now, this is an old thread and I'm posting to it from late 2018 and we're shipping a new Speculative mode in 2018.3 that works against all sorts of objects (and you can enable it on kinematic bodies too) but that's a whole different story I guess.

8. ### BrandyStarbrite

Joined:
Aug 4, 2013
Posts:
2,077
Wait! A new type of collider?

### Digital Ape

Joined:
Apr 11, 2010
Posts:
29,725
No.

Psyco92 likes this.
10. ### Jick87

Joined:
Oct 21, 2015
Posts:
124
Psyco92 likes this.

### Digital Ape

Joined:
Apr 11, 2010
Posts:
29,725
Yeah.

Psyco92 and Jick87 like this.
12. ### amitranegames

Joined:
Oct 23, 2013
Posts:
9
Bump
I am facing a weird issue with collision detection in Unity 2019.1.0f2.

I am making a Can Knock down kind of game.
I have attached a Sphere collider with rigidbody on the Ball. The Collision detection method is set to Continuous Speculative.

The Cans have Box collider on them with rigidbody set to Discrete.

Now the problem that I am facing is when I shoot the ball with swipe gesture, even if the ball passes close by any Can without even touching it, the collision is detected. (I tried changing it to Continuous, Continuous Dynamic but the result is same)

The same setup works perfect in Unity 2018.2 ( prior to Speculative Collision detection method) when the Collision detection method is set to Continuous Dynamic on Ball and Discrete on Cans.

PrimedAlpha likes this.
13. ### PrimedAlpha

Joined:
Dec 3, 2017
Posts:
1
I have almost the same problem as you. I use unity 2019.1. The rigidbody uses continuous speculative. I have it that when my axe(which rotates) enter a collision it’s set to kinematic = true. The problem is that my axe enters a collision even though it’s mid air. In the console it says it has collided but somehow it freezes mid air rather that at the collision point.

DrDigg0R likes this.
14. ### terresquall

Joined:
Mar 2, 2014
Posts:
29
The algorithm on continuous speculative is less accurate than the other modes, because it uses a speculative collision mode (predicts motion and pre-emptively detects collisions). I've done some research on collision modes before and wrote an article about it: https://blog.terresquall.com/2019/12/collision-detection-modes-in-unitys-rigidbody-component/

Continuous Speculative is even better. It collides against everything — static and dynamic objects in all modes of collision; is computationally faster than the other 2 modes of continuous collision; and detects certain kinds of collisions caused by spinning objects that are missed by other modes of continuous collision.

However, because it speculates (i.e. predicts) collisions based on objects' current motions, collisions that are detected can sometimes be inaccurate.

15. ### KarlKarl2000

Joined:
Jan 25, 2016
Posts:
611
Thanks so much for the information. Is Discrete the same thing as Continuous Speculative?

16. ### terresquall

Joined:
Mar 2, 2014
Posts:
29
Sorry for taking a month to get back to you!

Nope. It's not. Speculative uses a completely different collision detection algorithm (speculative vs. sweep-based) from the rest of the modes. Unity explains this in their docs: https://docs.unity3d.com/Manual/ContinuousCollisionDetection.html

17. ### murphyvjamese

Joined:
Apr 19, 2023
Posts:
4
Discrete performs collision detection based on the object's position in the current frame, whereas continuous considers the position of the object from the current frame and the previous frame.

As a result, a very fast object might pass all the way through a collider like a wall in a single frame. If you are using continuous, the line drawn between the previous and current frames will detect this, but if you are using discrete, the single point of reference will just assume that you somehow made it around the wall, and no collision is detected.

Thus, discrete is less computationally expensive, and can improve your game's performance, but comes at the cost of being less accurate than continuous.

peterkungen likes this.