Problem when addforce body keep rotate [SOLVED]

Rscorpiox

09-12-2008 07:26:41

I used a callback function to control my character

Sometimes they work pretty fine , but sometime when I pushed go stright

and then the body suddenly start to rotate...

I set the material like this

OgreNewt::MaterialID* m_pPlayerMat = new OgreNewt::MaterialID(m_World);
OgreNewt::MaterialID* m_pFloorMat = new OgreNewt::MaterialID(m_World);
OgreNewt::MaterialPair* m_pfPlayerFloor = new OgreNewt::MaterialPair(m_World,m_pPlayerMat,m_pFloorMat);

m_pfPlayerFloor->setDefaultElasticity(0);
m_pfPlayerFloor->setDefaultFriction(0.0,0.0);
player_body->setMaterialGroupID(m_pPlayerMat);
Terrain->setMaterialGroupID(m_pFloorMat);


and my forcecallback function is like this


Vector3 pos,inertia,move(0,0,0);
Ogre::Quaternion orient;
Real mass;

me->getMassMatrix(mass,inertia);
OgreNewt::BasicJoints::UpVector(m_World,player_body,Vector3(Vector3::UNIT_Y));

SceneNode *a=mSceneMgr->getSceneNode("NinjaNode");
me->getPositionOrientation(pos,orient);
orient = a->getOrientation();
me->setPositionOrientation(pos, orient);



Ogre::Vector3 V1 = orient * mDirection , V0 = me->getVelocity();
Ogre::Vector3 accel = (( V1 - V0 ) / me->getWorld()->getTimeStep());
move = accel*mass;
move.y = -9.8*mass;


me->addForce(move);


I set the body rotate just as my mesh.

and my Camera is using a sphere function around the mesh.

Just like most games.

Here's the code



SceneNode *a = mSceneMgr ->getSceneNode("NinjaNode");
//a ->translate(mDirection * evt.timeSinceLastFrame, Node::TS_LOCAL);


camPos.x = a ->getPosition().x + radious*cos(theta * 3.1415 / 180) * sin(omega * 3.1415 / 180);
camPos.z = a ->getPosition().z + radious*cos(theta * 3.1415 / 180) * cos(omega * 3.1415 / 180);
camPos.y = a ->getPosition().y + radious*sin(theta * 3.1415 / 180);


mCamNode ->setPosition(camPos);



"theta" is for xy and "omega" is for xz

I yaw and pitch my camera by this two degree to focus on my character.

I don't know if there's any bug in my code

Hope someone can give me some advise or better way to do this.

Thx all guys for reading this.

maybe it's a simple problem. plz don't blame me. :oops:

Rscorpiox

02-07-2009 14:11:51

Never Mind.

I set the body's Direction by other way.

And it's worked fine now. :D