This project is read-only.

Problem using JigLibX in my project

Jan 2, 2008 at 12:02 AM
I have been trying to make this work with my project (3d engine). When I add a box it falls correctly due to gravity for a couple of seconds then just disappears. It seems that after some random amount of time (usually around 1-3 seconds) it suddenly drops to around -100,000 on the Y axis and continues to drop at a huge rate. Changing gravity or its mass doesn't change anything (at least not enough to notice). I mostly copied the code from the example with a few tweaks (I'm fairly sure this is where it's going wrong). SetMass is exactly the same as the demo.

public override void Load(GraphicsDevice mDevice, ContentManager mLoader)
{
mModel = mLoader.Load<Model>(mAsset);

mBody = new Body();
mSkin = new CollisionSkin(mBody);
Vector3 sideLengths = new Vector3(1.0f) * mScale;

mSkin.AddPrimitive(new Box(-0.5f * sideLengths, Matrix.CreateFromQuaternion(mRot), sideLengths), (int)MaterialTable.MaterialID.UserDefined, new MaterialProperties(0.5f, 0.5f, 0.5f));
mBody.CollisionSkin = mSkin;

if (mStatic)
mBody.Immovable = true;

Vector3 com = setMass(1.0f);
mBody.MoveTo(mPos + com, Matrix.CreateFromQuaternion(mRot));
mSkin.ApplyLocalTransform(new Transform(-com, Matrix.Identity));
mBody.EnableBody();

mPhysics.AddBody(mBody);
}

Also if I add a box during the game it will also behave normally for a couple of seconds then drop as well.

Thanks
Developer
Jan 3, 2008 at 8:17 AM


.........
mBody.EnableBody();

mPhysics.AddBody(mBody);
}

Also if I add a box during the game it will also behave normally for a couple of seconds then drop as well.

Thanks


Why you are calling mPhysics.AddBody(mBody); method?
Jan 4, 2008 at 8:11 AM
I must have put that in trying to get it to work and never took it out. Anyway even if I remove that it does the exact same thing. It seems that if it has a mass of 1 and there is a gravity of 1 it drops exactly 50000 each frame. Freezing still effects it as if you set the gravity to very low it doesn't do anything. If you want any more information just ask.
Coordinator
Jan 4, 2008 at 12:21 PM
>> Anyway even if I remove that it does the exact same thing.

That's impossible. It should throw an error when you call EnableBody and then AddBody.:
JigLibXException("Collision skin was already added before");

Which version of JigLibX are you using? And you can also send me your code and i will have a look at it. jigglex@googlemail.com
Jan 5, 2008 at 3:40 AM
I figured it out. I was putting the elapsed milliseconds into integrate instead of seconds =(. Not sure how I missed that, should of been the first thing I checked. Anyway thanks for the help, its awesome now that its working!