Jittering with custom DetectFunctor
Forum » General / Help » Jittering with custom DetectFunctor
Started by: Andrew (guest)
On: 1257005077|%e %b %Y, %H:%M %Z|agohover
Number of posts: 6
rss icon RSS: New posts
Summary:
I have created a custom DetectFunctor. When collisions use it, they never rest on top of each other.
Jittering with custom DetectFunctor
Andrew (guest) 1257005077|%e %b %Y, %H:%M %Z|agohover

I created a custom DetectFunctor which handles collisions between the built-in JigLibX types (boxes, etc) and my custom terrain (built from model vertex data). It works as expected with the exception of when an object is in constant contact with the terrain. In that situation, the object will seem to vibrate on the surface (in the y-axis).

I think my issue is with returning the penetration distance. Here is the code below that is in question:

        public override void CollDetect(CollDetectInfo infoOrig, float collTolerance, CollisionFunctor collisionFunctor)
        {

        //SNIP!

                        Vector3 newPt = newPts[i], oldPt = oldPts[i];
                        float newDist;
                        Vector3 normal, collisionPosition;
            bool immediateCheck = customTerrainPrim.RayIntersect(out newDist, out collisionPosition, out normal, oldPt, newPt);
                        if (immediateCheck)
                        {
                            if (newDist < collTolerance)
                            {
                                float oldDist = collisionPosition.Y + collTolerance;

The rest of the DetectFunctor is taken from the BoxHeightMap one (included in JibLibX). The RayIntersect method checks for a collision on a plane along the vector starting at oldPt and going to newPt. It returns true if there is a collision, and then the distance to the plane (from the starting point), the point of the collision, and the normal of the collided plane.

Initially, I tried setting the penetration to the distance between the end point of the ray and the collision point; however, that resulted in objects falling through the custom terrain. Setting the penetration to the height of the terrain at the collision keeps objects above it, but they vibrate.

Any ideas? Or maybe more information on what the penetration represents?

Thanks!

unfold Jittering with custom DetectFunctor by Andrew (guest), 1257005077|%e %b %Y, %H:%M %Z|agohover
Re: Jittering with custom DetectFunctor
Andrew (guest) 1257011125|%e %b %Y, %H:%M %Z|agohover

I removed the condition for the ray intersect to return true before testing the distance against the tolerance. This stopped the vibration; however, the box object bounces once against the terrain and then falls through. It falls until the top set of points hit the terrain. Then it catches for a second and falls through again.

I think the problem is that the movement between collision checks is too great. So when the check is called again (after the box has bounced), the lowest points on the box have already moved below the terrain. Once they are below, the collision check function returns an infinite distance.

Is there a way to force the check to occur more often? Or can I return a more forceful collision to prevent the object from sinking?

unfold Re: Jittering with custom DetectFunctor by Andrew (guest), 1257011125|%e %b %Y, %H:%M %Z|agohover
Re: Jittering with custom DetectFunctor
Nic (guest) 1257034124|%e %b %Y, %H:%M %Z|agohover

Are you using a fixed timestep for your simulation? I noticed that when I started using a fixed timestep it got rid of most of my issues where physics meshes were penetrating to far into each other. The current step I've found that is decent for performance and works well, is 30hz, or every 0.0333333 seconds.

unfold Re: Jittering with custom DetectFunctor by Nic (guest), 1257034124|%e %b %Y, %H:%M %Z|agohover
Re: Jittering with custom DetectFunctor
Andrew (guest) 1257036832|%e %b %Y, %H:%M %Z|agohover

I am using a fixed timestep of 60hz. I tried increasing that to 1000hz and still got the bouncing behavior.

One thing I did notice, is that if I leave it to bounce for a few minutes it will eventually settle. So the issue seems to be too much energy being returned on impact. Is there a way to increase the dampening of collisions between two skins?

unfold Re: Jittering with custom DetectFunctor by Andrew (guest), 1257036832|%e %b %Y, %H:%M %Z|agohover
Re: Jittering with custom DetectFunctor
Nic (guest) 1257042806|%e %b %Y, %H:%M %Z|agohover

Here is what I'm initializing the PhysicsSystem to, you can see if that helps at all.

jigLibXPhysics = new PhysicsSystem();
jigLibXPhysics.CollisionSystem = new CollisionSystemGrid(32, 32, 4, 13, 13, 13);
jigLibXPhysics.EnableFreezing = true;
jigLibXPhysics.SolverType = PhysicsSystem.Solver.Normal;
jigLibXPhysics.CollisionSystem.UseSweepTests = true;
jigLibXPhysics.AllowedPenetration = 0.0001f;

I'm also using a heightfield for terrain, rather than a model, so I might not be seeing the same issues even if we had similar settings.

unfold Re: Jittering with custom DetectFunctor by Nic (guest), 1257042806|%e %b %Y, %H:%M %Z|agohover
Re: Jittering with custom DetectFunctor
PGlynnPGlynn 1257354885|%e %b %Y, %H:%M %Z|agohover

yea i agree with nic, if your trying to use a triangle mesh for a large surface you'll notice alot of hiccups. the heightmap approach is alot more solid.

unfold Re: Jittering with custom DetectFunctor by PGlynnPGlynn, 1257354885|%e %b %Y, %H:%M %Z|agohover
New post
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License