CCD Lag

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

CCD Lag

Post by imtrobin »

Hi

I have useContinuousDetectionAgainstMovingKinematics turned on, and I notice quite a noticable lag before the collision event is fired. I use it on a missile, it will stop when it hits the target for a second before it explodes. Because I have particles attached to it, it is very noticeable. Is there a way to reduce the lag time?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: CCD Lag

Post by Norbo »

There shouldn't be any noticeable wait time. There are two common cases where this can become visible however.

-If the missile is hitting an outer detector shape with which it has a noResponse CollisionRule and the space's simulationSettings.collisionDetection has useContinuousDetectionInNoResponsePairs set to true, it will be interrupted for a frame when it hits the detector.

-If the target is very large, the sweep test can fail due to insufficient floating point precision. This can manifest itself in a variety of ways, usually by stopping the object early or missing the collision entirely. If this is the cause, the rest of collision detection may have issues as well, accounting for a longer delay.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: CCD Lag

Post by imtrobin »

Yes I have useContinuousDetectionInNoResponsePairs set to true. Howver lag is more than a frame, it looks like almost a second. The objects are not big, the size are sphere radius 5 hitting against box 13.5x24x22.5

I have these settings too

Code: Select all

Space.simulationSettings.timeStep.timeScale = 1f; //If left unset, the default value is 1.
Space.simulationSettings.collisionResponse.iterations = 15; //If left unset, the default value is 15.
Space.simulationSettings.collisionDetection.defaultMargin = .04f;//Defaults to .04f
Space.simulationSettings.collisionDetection.defaultAllowedPenetration = .005f;//Defaults to .005f

Space.activateDynamicIterationCount (30    // fps
                                                    ,1     // min iteration
                                                    ,5);   // max iteration
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: CCD Lag

Post by Norbo »

To verify, the lag you're talking about is not a game-halting stop, but rather just a delay in between when you think the collision should occur and when the 'boom' happens, right? In other words, the game is running smoothly, but the event seems to occur late.

A video and/or reproduction case would help me diagnose the problem.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: CCD Lag

Post by imtrobin »

Yes, it is a lag with the collision while game is smooth. here's a video, the second missile lingers for a while too long. It's more obvious with a plane that's harder to reproduce.

http://envisagereality.com/downloads/te ... ormlag.avi
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: CCD Lag

Post by Norbo »

Do all of the moving kinematics involved in the collision have correct velocities relative to their movement? CCD is based on velocities, so significant errors in velocity might be noticeable.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: CCD Lag

Post by imtrobin »

Now you mentioned it, I think the AI guy is setting the position directly, not be velocities
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: CCD Lag

Post by imtrobin »

I have a video of the bullets, as you can see the bullets collision lag

http://envisagereality.com/downloads/te ... bullet.avi
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: CCD Lag

Post by imtrobin »

I have calculated and set the Entity.LinerVelocity when I set the Entity.worldTransform for the kinematic Entity, it still happens. The bullets and missiles go slo motion and won't hit as the chopper is slowly moving away. In the video, you can see the missile is paused. The bullet and missile has the right linearVelocity set once only, while the chopper is synchronizing with my worldTransform.

http://envisagereality.com/downloads/te ... ssile2.avi
http://envisagereality.com/downloads/te ... issile.avi
http://envisagereality.com/downloads/te ... bullet.avi
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: CCD Lag

Post by Norbo »

I think I'm going to need a reproduction case for this as well. I can't really say for sure right now, but setting the world transform from certain contexts at certain times might be doing it.

The problem in the video is similar to what happens to something you can see in the BEPUphysicsDemos. When the left-click ball has an extremely high velocity (so that the distance between the camera position and its graphic in the new frame is visible) and the button is held down, the CCD system will not allow the ball to go through other objects but the ball will not hit anything due to being moved backwards each frame because the left mouse button is pressed.

Here's an example timeline for the CCD system in the above case:

-Game.Update begins
Move Ball to camera, set to high velocity
-Space.update begins
Collision pairs (overlapping AABB's) found between high speed ball and environment
Minimum time of impact for high speed ball calculated
Ball advances only that amount of time forward
-Space.update ends
-Game.Update ends

-Game.Update begins
Move Ball to camera, set to high velocity
-Space.update begins
Collision pairs (overlapping AABB's) found between high speed ball and environment
Minimum time of impact for high speed ball calculated
Ball advances only that amount of time forward
-Space.update ends
-Game.Update ends

and so on. The ball never gets to create any contact points with the environment because it is always moved back at the beginning of the next frame. To create contacts, there must be a frame where the ball is actually near another entity.
Post Reply