Problems moving a rigid body with the mouse

James321
Posts: 1
Joined: Sun Mar 30, 2014 9:50 pm

Problems moving a rigid body with the mouse

Post by James321 »

Hey, (I'm using irrlicht btw)

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));
I would appreciate an help/examples which could fix my problem

Also suggestions of a better way to do it are welcome