I'm making a small side scrolling game for my class, which involves clicking on and moving objects.
I have this section of code in my entity's update method which moves it towards the users cursor. This works fine but when it reaches the users cursor it "jitters" past the mouse pointer and then back and so on.
Code: Select all
core::line3d<f32> ray = game.getDevice()->getSceneManager()->getSceneCollisionManager()->getRayFromScreenCoordinates(inputHandler.getCurrentMouse().Position);
vector3df characterPos = getNode()->getPosition();
vector3df targetPos = ray.getClosestPoint(getNode()->getPosition());
vector3df direction = targetPos - characterPos;
direction = direction.normalize();
direction *= 10;
btVector3 dir = btVector3(direction.X,direction.Y,0);
getRigidBody()->activate();
getRigidBody()->setLinearVelocity(dir);
_rigidBody->setLinearFactor(btVector3(1,1,0));
_rigidBody->setAngularFactor(btVector3(0,0,1));
Also suggestions of a better way to do it are welcome