PlayerController not moving body

Boogy

24-03-2010 12:11:37

I am currently working on a race game. And I'm using the OgreNewt::PlayerController for controlling the car. The problem is that the car won't move. It turns but it doens't move forward nor backward.

This is the code I use to create the body:

m_Body = new OgreNewt::Body(m_World, m_CollisionHull);
m_Mass = 100.0f;

Vector3 inertia, offset;
m_CollisionHull->calculateInertialMatrix(inertia, offset);
m_Body->attachNode(m_Node);
m_Body->setMassMatrix(m_Mass, inertia*m_Mass);
m_Body->setCenterOfMass(offset);
m_Body->setStandardForceCallback();

m_Body->setPositionOrientation(m_Position, FrameWork::getSingletonPtr()->m_GameCam->getDerivedOrientation());
m_Body->setVelocity(Vector3(0,0,0));
m_Body->setAutoSleep(0);

m_Controller = new OgreNewt::PlayerController(m_Body, 5);


This piece of code I use to move the player. m_Up etc. get set when the player presses one of the arrow keys.
The car turns but doesn't speed up. Is there a function call I'm forgetting?

if(m_Up) m_CurrentSpeed += m_Acceleration;
else if(m_Down) m_CurrentSpeed -= m_Acceleration;

if(m_Left) m_Angle += 2 * a_DT;
else if(m_Right) m_Angle -= 2 * a_DT;

CalculateDirectionVector();
m_CurrentSpeed *= 0.98f;
if(m_CurrentSpeed > MAX_SPEED) m_CurrentSpeed = MAX_SPEED;
else if(m_CurrentSpeed < MIN_SPEED) m_CurrentSpeed = MIN_SPEED;

m_Controller->setVelocity(m_CurrentSpeed, m_CurrentSpeed, Radian(m_Angle));
m_Body->getVisualPositionOrientation(m_Position, m_Orientation);

ChengFengYeh

08-08-2010 10:01:12

Hi,
I found that once you call "m_Body->setPositionOrientation()" to set the postion, then you will encounter this situation with PlayerController.
So, try to avoid to call "m_Body->setPositionOrientation()"?