I create a body, with a collision and then i check when a key is pressed:
-----------------------------------------------------------------------------------
if(tasti[irr::KEY_KEY_W])
{
speed=500;
}
else if(tasti[irr::KEY_KEY_S])
{
speed=-500;
}
else
speed=0;
---------------------------------------------------------------------------------
then I apply the force on the body:
--------------------------------------------------------------------------------
if(speed)
{
//I take my camera target direction:
dir= camera->getTarget() - camera->getPosition();
dir.normalize();
// I Apply the force on my body.
setForce((dir*speed));
//I set the body rotation:
NewtonBodyGetMatrix(body,GetMatrixPointer(temp_mat));
temp_mat.setRotationDegrees(camera->getRotation()*IrrToNewton);
NewtonBodySetMatrix(body,GetMatrixPointer(temp_mat));
//I Update my graphics node position
nodePosition=temp_mat.getTranslation()*NewtonToIrr;
//I change the camera position
camera->setPosition( nodePosition);
vNode->setPosition(nodePosition);
//I set the actual position as previous position
prevPos=nodePosition;
moving=1;
}
else
{
moving=0;
vNode->setPosition(prevPos);
camera->setPosition(prevPos);
NewtonBodyGetMatrix(body,GetMatrixPointer(temp_mat));
temp_mat.setTranslation(prevPos*IrrToNewton);
NewtonBodySetMatrix(body,GetMatrixPointer(temp_mat));
//If i'm not moving with W,A,S,D.. etc i set a 0 Force
setForce(vector3df(0,0,0));
}
-------------------------------------------------------------------------------------
The problem is: When i Check the force applied on my body with: [ NewtonBodyGetForce(n_body,tf2); ]while i'm not moving:
X=0, Y=0, Z=0;
but my body is still slowly moving till it stops, as in the real world when you launch an object and this is moving till the energy on it is not sufficent to move it.
The problem is that I need My body to stop when i apply a 0 Force. how can I do ?