Gravity problem

Celest

04-10-2008 11:05:18

How can I resolve Figure A to result Figure B



This code seems don't have gravity included.

OgreNewt::CollisionPrimitives::Cylinder* col = new OgreNewt::CollisionPrimitives::Cylinder( newtWorld , 4 , 21, Quaternion(Degree(90),Vector3::UNIT_Z) , Vector3(0,10.5,0));
body = new OgreNewt::Body(newtWorld, col);
body->attachToNode(node4);
body->setMaterialGroupID(material);

inertia = OgreNewt::MomentOfInertia::CalcCylinderSolid( mMass, 4 , 21);
body->setMassMatrix( mMass, inertia );
body->setCustomForceAndTorqueCallback<player_stat>(&player_stat::forceCallback,this);
body->setAutoFreeze(false);

OgreNewt::Joint* joint = new OgreNewt::BasicJoints::UpVector(newtWorld,body,Vector3(Vector3::UNIT_Y));



void forceCallback(OgreNewt::Body* body)
{
body->addForce(mGravity * mMass);

Vector3 characterDirection = mTarget - node4->getPosition();
characterDirection.normalise();

Vector3 desiredVelocity = characterDirection * speed;

Vector3 forceApply = ((desiredVelocity - body->getVelocity()) * mMass ) * 60;

body->setForce(forceApply);

Vector3 pPos;
Quaternion pOri;

body->getPositionOrientation(pPos,pOri);
}

BardockSSJ

04-10-2008 12:52:47

Add gravity after body->setForce(forceApply);, because setForce cleans all forces before.

Celest

04-10-2008 12:59:07

Add gravity after body->setForce(forceApply);, because setForce cleans all forces before.

Did you mean "body->addForce(mGravity * mMass); " ?
I tried that. But it doesn't work.

nullsquared

04-10-2008 16:30:56

Tried using addForce() instead of setForce().