I've got some issues with my models and applying physics to them.
I use this code to initialize the body and collision skin within my model-class:
body = new Body(); collision = new CollisionSkin(body); body.CollisionSkin = collision; BoundingBox bbox = ModelService.getModelBBox(this); Vector3 sideLengths = new Vector3(Math.Abs(bbox.Max.X - bbox.Min.X), Math.Abs(bbox.Max.Y - bbox.Min.Y), Math.Abs(bbox.Max.Z - bbox.Min.Z)); bodyBox = new Box(Position, this.Orientation, sideLengths); collision.AddPrimitive(bodyBox, new MaterialProperties(0.8f, 0.7f, 0.6f)); Vector3 com = SetMass(100.0f); PhysicsSystem physics = Engine.GetService<PhysicsSystem>(); body.MoveTo(this.Position, this.Orientation); body.CollisionSkin.ApplyLocalTransform(new Transform( -com, this.Orientation)); body.EnableBody(); physics.AddBody(body); this.Parent = Engine.Root;
with the SetMass() method copied from the JigLibX-Tutorial here in this wiki.
Everything works perfectly fine. The problems comes with my update method, which looks like this:
this.Position = body.Position; this.Orientation = body.Orientation;
The issue I'm having is that my models seem to float in the air. I suspect the reason for that is that I created my models with their pivot-point moved to their bottom (x, 0, z)
Since the Body's position seems to be in the center of the box, the models float above the ground in height of boxHeigt/2.
Is there any way to work around this problem, without having to change my models' pivot-points to their center?
Since all my models have their pivot points at the bottom it would be good enough for my project to modify the Box-Code in JigLibX so that it's pivot point would not be centered but also moved to the bottom. How can I do that?
Tanks in advance ;)