controling characters moving make a mistake?

sxk8087

27-08-2008 04:57:05

I use "Body->setVelocity()" to control characters moving forward.
"Body->setOmega()" to Rotate. But making characters move forward for a period of time. The characters will not move no matter what I do
(Such as press Key'W','S','A','D'). my code is :
if (keyboard->isKeyDown(KC_W))
{
mDirection = mMainNode->getOrientation() * ctor3::UNIT_X;
mDirection.y = 0;
Body->setVelocity(mDirection);
}
if (keyboard->isKeyDown(KC_A))
{
mDirection = mMainNode->getOrientation()*Vector3::UNIT_X;
mDirection.y = 0;
Body->setVelocity(mDirection);
Body->setOmega(Vector3(0,1,0));
}
I can control it at the beginning,but after it I can not control until the last. Other,I want to know how you control characters.
I am sorry that my English is poor.I hope you understand my meaning

micken

27-08-2008 05:08:25

Make sure you are updating your world every frame (i.e. mWorld->update();)

If this is not the problem please post more information on how you are creating and managing the body you are trying to move.

sxk8087

27-08-2008 07:34:36

My code is: bool frameStarted(const FrameEvent& evt)
{ ................................
mWorld->update(true);
if (keyboard->isKeyDown(KC_W))
{
mDirection = mMainNode->getOrientation() * ctor3::UNIT_X;
mDirection.y = 0;
Body->unFreeze();
Body->setVelocity(mDirection);
}
if (keyboard->isKeyDown(KC_A))
{
mDirection = mMainNode->getOrientation()*Vector3::UNIT_X;
mDirection.y = 0;
Body->unFreeze();
Body->setVelocity(mDirection);
Body->setOmega(Vector3(0,1,0));
} .........................
}
void createScene(void)
{ .......... //"mNode" is floor node, is fixed
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::TreeCollision(mWorld, mNode, true );
OgreNewt::Body* Body = new OgreNewt::Body(mWorld, col );
delete col;
Body->attachToNode( mNode );
//"mMainNode" is character's node
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::ConvexHull(mWorld,mMainNode);
Body = new OgreNewt::Body(mWorld,col);
Body->attachToNode( mMainNode );

Body->setPositionOrientation( Ogre::Vector3(30,0,0),Ogre::Quaternion::IDENTITY);
delete col;

Ogre::Real mass = 10.0;
Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcCylinderSolid( mass, 0.5, 0.7);
Body->setMassMatrix( mass, inertia );
Body->setStandardForceCallback();
}

micken

28-08-2008 01:31:30


mWorld->update(true);

This is most likely your problem. You need to pass the time since the last frame to the update function so OgreNewt knows how much time to simulate.

mWorld->update(evt.timeSinceLastFrame);



Body->unFreeze();

OgreNewt has the tendency to freeze things. If your object is being controlled by the user then it makes a lot of sense to use setAutoFreeze(false) on it when you create it so that it will never be frozen.

Body->setAutoFreeze(false);

sxk8087

28-08-2008 05:09:44

Thank you very much. I was successful .