Need help with gravity and collision

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Nadeeja
Posts: 17
Joined: Wed Oct 05, 2011 6:23 am

Need help with gravity and collision

Post by Nadeeja »

Hey everybody,
So I started using Bepu recently and I'm pretty new to game developing.I have some problems -

After searching for hours I finally got an object to fall to the ground.But there seems to be something wrong, the object falls to the ground at a constant velocity.
Gravity is supposed to accelerate falling objects right? This is the code -

Code: Select all

Entity testshape;  

//Load Content
Space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0);

Testobj = Content.Load<Model>("Models\\testshape");

            testshape = new Capsule(new Vector3(0, 100, 0), 100, 10,10);
            Space.Add(testshape);

//Update
Space.Update();

//Draw

Matrix[] testobjtransforms = new Matrix[Chamber.Bones.Count];
            Testobj.CopyAbsoluteBoneTransformsTo(testobjtransforms);
            foreach (ModelMesh mesh in Testobj.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.World = testobjtransforms[mesh.ParentBone.Index] *
                       Matrix.CreateRotationY(MathHelper.ToRadians(90)) * testshape.WorldTransform ; //This is the part I'm unsure.Is this OK?

                    effect.Projection = projection;
                    effect.View = view;

                }
                mesh.Draw();
            }

And also, changing the mass of the capsule doesn't seem to make any difference... Anybody knows what I'm doing wrong?

Thanks for your time.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Need help with gravity and collision

Post by Norbo »

If you haven't already, checking out the getting started demo and associated documentation would be useful: http://bepuphysics.codeplex.com/wikipag ... umentation

There's also ~40 example simulations in the BEPUphysicsDemos project within the main source download: http://bepuphysics.codeplex.com/SourceC ... changesets
testshape = new Capsule(new Vector3(0, 100, 0), 100, 10,10);
That is quite a large cylinder. A gravity of (0, -9.81, 0) implies the units are in meters. That cylinder is 100 meters tall, the size of a large building (a little more than a fourth the height of the Empire State Building). When it falls, it will appear to fall relatively slowly if you expect it to behave like a toy or car-sized object.

With objects that size and up, you should also watch out for numerical issues. The engine prefers objects to be in the 0.5 to 10 units range. This makes collision detection faster and more robust.

If the object is truly moving at a constant rate as opposed to an accelerating rate, it may not actually be falling. Look at the velocity using the debugger to verify what's happening (or scale things so that it's easier to see it accelerating).
And also, changing the mass of the capsule doesn't seem to make any difference
Changing the mass of an object does not change the acceleration due to gravity. Gravity boils down to a simple acceleration because gravitational force scales with mass.
effect.World = testobjtransforms[mesh.ParentBone.Index] *
Matrix.CreateRotationY(MathHelper.ToRadians(90)) * testshape.WorldTransform ; //This is the part I'm unsure.Is this OK?
That looks fine. The first matrix positions the entity as needed in local space, the second rotates it (presumably into alignment with the collision geometry), and the third pulls it into world space. The GettingStartedDemo shows a simple DisplayModel class that follows an entity.

However, I would recommend jumping into the BEPUphysicsDemos simulations and fiddling around with different configurations for a while. That will get you a feel for how the physics engine works in isolation without worrying about rendering things. Graphics and all that are totally separate from the physics engine.
Nadeeja
Posts: 17
Joined: Wed Oct 05, 2011 6:23 am

Re: Need help with gravity and collision

Post by Nadeeja »

Thanks Norbo!
Scaling the size down actually worked. :D
Changing the mass of an object does not change the acceleration due to gravity. Gravity boils down to a simple acceleration because gravitational force scales with mass.
Silly me :oops:


By the way I'm having trouble with convex hull. It's really hard to tweak it without actually seeing it.So I got the BepuPhysicsDrawer which came with the GettingStartedDemo but have no idea how to use the DisplayConvexhull and display the shape.
If you can post a little example on that, that'll be great :D
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Need help with gravity and collision

Post by Norbo »

Some of the documentation demos, like the one used by internal multithreading, show examples of how to use the model drawers.

Basically, you create a ModelDrawer (either a InstancedModelDrawer or BruteModelDrawer depending on the graphics profile) and add entities or other recognized types to it. Then, call the ModelDrawer's update method and draw method.
Post Reply