Stop a Moving Body when a 0,0,0 force is applied

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Stop a Moving Body when a 0,0,0 force is applied

Postby Nutu » Sat May 15, 2010 10:09 am

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 ?
Nutu
 
Posts: 4
Joined: Sat May 15, 2010 9:54 am

Re: Stop a Moving Body when a 0,0,0 force is applied

Postby Julio Jerez » Sat May 15, 2010 3:59 pm

if you are going to do it that way, then you can set velocity to zero when you set the force to zero.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Stop a Moving Body when a 0,0,0 force is applied

Postby Nutu » Sun May 16, 2010 4:58 am

Thanks a lot Julio ^^, you was very helpfull to me
Now it works fine and i can go on with my work, (a little game project for my school ).
Nutu
 
Posts: 4
Joined: Sat May 15, 2010 9:54 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron