box to box collision

Jan 1, 2010 at 12:40 AM

Hi there,

First of all, thanks for this engine. It is amazing the impressive things one can do with a couple of lines of code.

I have a problem though with the collision of the boxes. I have spent already a couple of hours trying to figure out what I did wrong, but I am too noob.

I modified the example1 and made a box movable by the "player" (with asdw). While I move around the collisions seem to be detected ok, until i find some boxes, which I go through (!). I have tried to find a difference between the boxes whose collision is working ok and those where it doesn't (with the debugger), without success. After I recreate the boxes, (with R) the boxes whose collision don't work are a different set, but I always find some which don't work.

What am I doing wrong? Please help!

My project is here:



Jan 1, 2010 at 4:21 PM

Just an update.

after removing the random positioning of the boxes, I can't reproduce this problem anymore. It seems like the collision disables "itself" when the overlapping surpasses some sort of threshold (?)



Jan 1, 2010 at 11:27 PM
Edited Jan 1, 2010 at 11:27 PM

Hey julodnik,  I took a look at the code you modifed.  I belive the issue is that you create a sphere with a radius of zero.  Take a look at your ExampleScreen.Rest(int, int) method (issue heightlighted in red):

// Iterate on all sphere shapes.
         for (int i = 0; i < sphereCount; i++)
            // Create the collision sphere.
            CollisionSphere sphere = new CollisionSphere();
            sphere.Radius = i; // < 4 ? 7.0f : (float)(random.NextDouble() * 3.0D) + 1.0f;
            sphere.StaticFriction = i < 4 ? 1.0f : 0.7f;
            sphere.DynamicFriction = i < 4 ? 1.0f : 0.7f;
            sphere.Restitution = 0.8f;

            // Create a rigid body for the collision sphere.
            RigidBody rigidBody = new RigidBody();
			rigidBody.Flags = RigidBodyFlags.AutoDisable;
            rigidBody.AngularDamping = 0.3f;

            // Add collision sphere to the rigid body.

            // Determine the position and orientation of the sphere.
            Vector3 position =
               random.NextVector3(-90.0f, 90.0f, i, i, -90.0f, 90.0f);
				Quaternion orientation = Quaternion.Normalize(random.NextQuaternion(-90.0f, 90.0f, 50.0f, 70.0f, -90.0f, 90.0f));
            Matrix orientation = Matrix.CreateFromQuaternion(Quaternion.Normalize(random.NextQuaternion(-90.0f, 90.0f, 50.0f, 70.0f, -90.0f, 90.0f)));
            rigidBody.UpdateTransform(ref position, ref orientation);

            rigidBody.Rotation = new Vector3(1, 1, 1); //random.NextVector3(-0.5f, 0.5f);

            // Assign the sphere to the quad-tree and shape list.

This will cause all sorts of issues with the CollisionSystem, mainly with the SweepAndPrune.   You could change it "sphere.Radius = i + 1;" or something.

 Hope that helps.  Good luck!