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:
This code works fine, but when I try the same with my "people" I get strange results. The code is:
Movement:
Turning:
Where people follow the camera, the direction is calculated as:
When I created the people I limited their rotation in the x and z axis, and set the damping:
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
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