I'll get right into the problem. I'm using IrrBullet for my physics engine and I'm currently working on a character controller. The character controller is a box that has an affector, ICollisionObjectAffectorAttract, pulling it towards a point (the center of a globe I'm using as a map)
Code: Select all
ICollisionObjectAffector * affector = new ICollisionObjectAffectorAttract(Game::instance()->returnObjects()->returnWorld()->getPosition(), mass*1333);
Code: Select all
// CONTROL MOVEMENT
vector3df velocity(0,0,0);
vector3df localForward(0,0,0);
const matrix4& mat = Camera->getAbsoluteTransformation();
f32 MoveSpeed = movement;
if(Game::instance()->returnReceiver()->IsKeyDown(KEY_KEY_W))
localForward.Z = MoveSpeed;
if(Game::instance()->returnReceiver()->IsKeyDown(KEY_KEY_S))
localForward.Z = -MoveSpeed;
if(Game::instance()->returnReceiver()->IsKeyDown(KEY_KEY_A))
localForward.X = -MoveSpeed;
if(Game::instance()->returnReceiver()->IsKeyDown(KEY_KEY_D))
localForward.X = MoveSpeed;
mat.rotateVect(velocity, localForward);
velocity.Y = 0.0f;
Body->setLinearVelocity(velocity*2000);
I tried this code, it does account for the affector but just causes the velocity to exponentially increase every step:
Code: Select all
Body->setLinearVelocity(Body->getLinearVelocity+(velocity*2000));