Body movement and rotation

netsurferj

13-07-2008 20:43:56

Hi

I have implemented people in my game as bodies. For the camera I created a body and attached the camera to its scene node. To move I used this code:
mDirection.y = camBody->getLinearVelocity().y;
Quaternion q = mCamera->getOrientation();
Vector3 v = q * mDirection;
v.y = mDirection.y;
camBody->setLinearVelocity(v);

This code works fine, but when I try the same with my "people" I get strange results. The code is:
Movement:
direction.y = mBody->getLinearVelocity().y;
Vector3 src = mBody->getGlobalPosition()*Vector3::UNIT_X;
Quaternion q = src.getRotationTo(direction);
Vector3 v = q * direction;
v.y = direction.y;
mBody->setLinearVelocity(v);


Turning:
Vector3 src = mBody->getNode()->getOrientation() * Vector3::UNIT_X;
Ogre::Quaternion quat = src.getRotationTo(direction);
mBody->setGlobalOrientation(quat);


Where people follow the camera, the direction is calculated as:

direction = camBody->getGlobalPosition() - mBody->getGlobalPosition;


When I created the people I limited their rotation in the x and z axis, and set the damping:
mBody->raiseBodyFlag(NxBodyFlag::NX_BF_FROZEN_ROT_X);
mBody->raiseBodyFlag(NxBodyFlag::NX_BF_FROZEN_ROT_Z);
mBody->setAngularDamping(0.5);


During gameplay the characters only moves because of the uneven terrain and gravity, but they turn in weird ways, and very gittery. Sometimes some of the characters shoots off into the sky (even with the movement code disabled).

I am using 0.9.

thanx

netsurferj

14-07-2008 11:02:53

I noticed that the bodies tilts in the x and z direction (falls on their faces) although I "locked" rotation in x and z. Can anyone see any problems with my code, as I have tried many different things, but nothing seems to work?

netsurferj

21-07-2008 19:22:24

Finially got it working. After attaching the camera to the scene node, I simply yaw and pitch the camera:
mCamera->yaw(Degree(-mRotate* mMouse->getMouseState().X.rel));
mCamera->pitch(Degree(-mRotate * mMouse->getMouseState().Y.rel));


To move the camBody using force I used this code:
Quaternion q = mCamera->getOrientation();
Vector3 v = q * mDirection;
camBody->setLinearVelocity(v);


I found that using setLinearVelocity does not let the camera slide too far when the button is released.