BulletPhysics (.net) Can't seem to get collisions working

Post Reply
pixartist
Posts: 8
Joined: Thu Jan 15, 2015 5:07 pm

BulletPhysics (.net) Can't seem to get collisions working

Post by pixartist »

Hi, I'm working with the .net binding of Bullet and I can't seem to get the physics working properly. I use this to start the physics engine:

Code: Select all

var collisionConfig = new BulletSharp.DefaultCollisionConfiguration();
            PhysicsWorld = new BulletSharp.DiscreteDynamicsWorld(
                new BulletSharp.CollisionDispatcher(collisionConfig), 
                new BulletSharp.DbvtBroadphase(), 
                new BulletSharp.SequentialImpulseConstraintSolver(), 
                collisionConfig);
Now I add some cubes like this:

Code: Select all

public void SetCollisionBox(Vector3 center, Vector3 scale)
		{
            SetBody(new BoxShape(0.5f), center, scale);
		}

private void SetBody(CollisionShape shape, Vector3 center, Vector3 scale)
		{
			Center = center;
			ClearBody();
            RigidBodyConstructionInfo info = new RigidBodyConstructionInfo(1, new DefaultMotionState(Matrix4.CreateTranslation(Transform.Position) + Transform.Rotation.ToMatrix4()), shape);
			Body = new RigidBody(info);
            Body.CollisionShape.LocalScaling = scale;
            
            GameObject.App.PhysicsWorld.AddRigidBody(Body);
		}
Now these cubes seem to at least collide with each other and are certainly affected by gravity. But I wanted to create a baseplate (a cube) with static behaviour, using this method:

Code: Select all

public void MakeStatic()
        {
            if (Body != null)
                Body.SetMassProps(0, Vector3.Zero);
        }
And the cubes are just falling through. What am I missing ?
anthrax11
Posts: 72
Joined: Wed Feb 24, 2010 9:49 pm

Re: BulletPhysics (.net) Can't seem to get collisions workin

Post by anthrax11 »

Matrices should be multiplied, not added.
new DefaultMotionState(Matrix4.CreateTranslation(Transform.Position) * Transform.Rotation.ToMatrix4()

I tried adding translation and rotation matrices in BulletSharp and the effect was indeed that it looked the same visually, but there were no collisions because the matrix was somehow messed up and was confusing the physics engine.
pixartist
Posts: 8
Joined: Thu Jan 15, 2015 5:07 pm

Re: BulletPhysics (.net) Can't seem to get collisions workin

Post by pixartist »

Ha, I'm an idiot. Thanks, that was my mistake!
Post Reply