This project has moved and is read-only. For the latest updates, please go here.

Geometry irrational behavior

Apr 26, 2010 at 9:00 PM
Edited Apr 26, 2010 at 9:00 PM


I have one trouble with engine.

I created a Body and a Geometry for this body, lets name it body1. The body1 is rectangle. I set its parameter static = true.

After that i created another Body with Geometry, lets name it body2. It`s not a static.

If body2 has speed in the direction of body1 and it collide with body1, often body2 begin rotating very quickly (crazy) and then it desappears and i have this error

And second  trouble. If body2 has enough big velocity it can move throughout the body2 and sometimes it gets stuck in body2.

May be you can help me.

Thank you.



Apr 26, 2010 at 10:45 PM

Are there any spring joints attached to body2?

Apr 27, 2010 at 10:16 AM

No, i do not use any joints at all.

Apr 27, 2010 at 5:46 PM

Regarding the first problem, what shape is the second geometry, and how fast are you making them collide?  I can't imagine why that would be happening.

Your second trouble may be remedied in the upcoming version 3.0.  It has a whole lot new high techy goodness.  I remember seeing some property on Body specifically to remedy this problem.  Your first problem may even be fixed too with the new narrowphase collision.

Apr 27, 2010 at 10:50 PM

About the first problem:

body2 is rectangle too


protected static float LINEAR_DRAG_COEFFICIENT = 300.0f;

protected static float FORCE = 1800.0f;


// body1 creation

            bridgeLeftOuterSide = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, 7, 206, 1000);
            bridgeLeftOuterSide.Position = new Vector2(532, 540);
            bridgeLeftOuterSide.IsStatic = true;
            bridgeLeftOuterSideGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, bridgeLeftOuterSide, 7, 206);

// body2 creation

body2 = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, 28, 16, 100);

body2.LinearDragCoefficient = LINEAR_DRAG_COEFFICIENT;

body2.RotationalDragCoefficient = 100000;

body2Geometry = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, boxBody, 28, 16);


// In that way i send body2 fixed impulse value and maximum velocity is fixed

body2.ApplyImpulse(new Vector2(FORCE * (float)Math.Cos(boxBody.Rotation), FORCE * (float)Math.Sin(boxBody.Rotation)));


Apr 29, 2010 at 5:43 PM

How frequently is that last ApplyImpulse line called?  Every frame, or every once in a while?  If it's called every frame, you should switch to ApplyForce.  Otherwise.... I have no idea. =[

Apr 30, 2010 at 10:09 PM

Yota, thanks for your participation in resolving my problems.

ApplyImpulse called permanently - its a car speed increasing function. Once in a while.

I tried to replace Impulse with Force - the same effect.

Today i decided to be easy and smarty :) and i fixed this defect so as i do my usual work

I restricted the problem variable from above in Body.cs:

with defect:

//Calculate rotational drag and apply it as torque
            _rotationalDrag = AngularVelocity * AngularVelocity * Math.Sign(AngularVelocity);  // AngularVelocity variable is so large after collision that it becomes a Non Numeric Value and falls down therefore in this line
            _rotationalDrag *= -RotationalDragCoefficient;


with my fixing:

//Calculate rotational drag and apply it as torque
            if (AngularVelocity > 10)  // simple but effective :)
                AngularVelocity = 10;
            _rotationalDrag = AngularVelocity * AngularVelocity * Math.Sign(AngularVelocity);
            _rotationalDrag *= -RotationalDragCoefficient;

It DO works )))

Thanks for help.