how to bring an moving object to stop

Hi Guys

I have an rigid-body object to which I have added force in a particular direction. I want to be able to bring this object to a stop when I press a certain key.

void object_movement(){
if(Input.GetKey(KeyCode.Space)){
jump = jump + setjumpheight;
object.rigidbody.AddForce(0.0f,jump,0.0f);
}
else{
if(Input.GetKey(“up”)){
speed = speed + incrementspeedby;
object.rigidbody.AddForce(0.0f,0.0f,speed);
}
}

if(Input.GetKey(“down”)){
speed1 = decrementspeedby - speed;
object.rigidbody.AddForce(0.0f,0.0f,speed1);
}
}

this is the function that I am calling in my
Void Updated() function.

the current result is the on pressing the down arrow key the objects starts moving in the opposite direction. Instead I want the object to come to a stop.

Try setting this On ?

Hey AkilaeTribe

Thanks for the help, also 1 more thing right now if I turn on the “IS Kinematic” property ON the object comes to a halt immediately instead if I want it to come to a halt gradually what should I do? some thing like applying brakes.

thanks again.

Increase the air resistance (Drag), maybe ?

Plus a Mathf.Lerp to simulate the increase.

Hey thank I will check it out :smile: