- Home /
Issues with Continuous Dynamic collision.
I'm rolling a fast moving ball that has a spherical collider set to Continous Dynamic collision detection for most precise collision detection. The objects it's colliding with are capsule colliders set to Continous detection.
Now, this is the recommended configuration for detecting collision for fast moving objects in Unity. However, I'm 'occasionally' seeing the ball still sneak through the colliders at indeterminate times.
From my understanding of Continous Dynamic collision, this shouldn't be possible (unless you screw up such as scaling the parent of the rigid body or directly set translation on the rigidbody while it's moving - neither of which I'm doing.)
So I expect this to be working. Any ideas how or why Continous Dynamic could still occasionally skip collisions? I don't want to have to resort to using ray casting to ensure collision if I don't have to.
I've already searched the forum and haven't seen mention of this exact issue, so I'm trying to figure out where I must be going wrong on this...
Answer by Andy Korth · Mar 24, 2011 at 08:50 PM
Your ball passes through the capsule colliders because it's velocity is so high that the distance it moves from one frame to another will bring it from one side of the capsule to the other without ever having overlapped the collider.
By reducing the timestep, more intermediate positions are calculated, and the collision is more likely to be found. That's what you've done by adjusting your timestep.
Swept collisions (also called continuous collision detection) work by determining the path of the objects as they move between frames, to determine if fast moving object's paths have collided between frames. So it should solve your problem. However, in simple replication projects, I've noticed issues with the continuous collision detection. I've filed bug 389071 with Unity, but I haven't heard back about it.
Yep, I'm aware of how all the collision does work, but the issue I was having is that even though I had Continuous Dynamic turned on for the moving object, and Continuous set for the objects collided with, collision was still periodically failing detection. This was not supposed to be possible with Continous Dynamic turned on, yet that's what is happening.
Yeah, so I'm glad it's not just me who thinks it's buggy.
I'm seeing the same thing - a moving ball passing through a fast-moving capsule. The capsule just rotates though.. like a pinball flipper. I've tried all manner of 'continuous' settings on the bodies to no avail. Will try the time step solution.
I just tried continuous dynamic on my rigidbodies. One of them is a kinematic object is moved with $$anonymous$$ovePosition in FixedUpdate.. but it lets objects pass through at high speeds. Tried this in Unity 4.1.3
Answer by efge · Mar 15, 2011 at 07:29 PM
You could try to solve this by adjusting the settings in the Physics Manager and the Fixed Timestep in the Time Manager.
Good point. I'll give that a try and see how it goes.
Decreasing the time step definitely helps. I haven't seen it get through yet since I changed it. But I'm having to set fixed timestep to less than 0.02 which was already 50 times a second. The worry for me now is that this is on iPhone, and that may just be way too heavy on the cpu. Hrm.
Answer by Bezzy · Sep 05, 2012 at 01:34 PM
I've managed to come up with pretty rock solid movements for high speed bullets, testing against each other (well, actually, each bullet has a "bullet detector" trigger collider on it, in a different layer which only listens for the bullet collider's layer (non triggers). Bullets don't directly interact with one another - only via their detectors.
I made the bullet a capsule, pointing along its Z (as that's the relative axis it always travels along in this case).
I then calculate how far the bullet moves during one physics step by multiplying the muzzle velocity by Time.fixedDeltaTime
I then set the height of the capsule to that displacement step size (but also take into account the radius of the capsule affecting height).
Thus, even at very high speeds, there will be a frame where the bullet collider overlaps the bullet detector, and the bullets will not pass through one another.
Very good performance, and works well with object pooling.
Haven't tried it with varying bullet speed (i.e. varying collider height), but I've little reason to think it'd stop working, so long as the height changes are made in a FixedUpdate step.
Also, this is kind of the equivalent of a collider sweep, but I've found that to be highly susceptible to floating point inaccuracies -not insurmountable, but a real rathole)
This is an awesome comment, you just solved my continuous dynamic bullet problems! Thank you!
I'm definitely up-voting that comment. Great idea Bezzy!!
Your answer
Follow this Question
Related Questions
Continuous collision detection - unnatural behaviour 0 Answers
How to perform grasp action on a cloth? 3 Answers
Two Moving Sphere Colliders with Continuous Dynamic miss each other 2 Answers
Rigid body Continuous and ContinuousDynamic seem to do nothing 1 Answer
FPS Tutorial: Why do my grenades go through the walls? 3 Answers