- Home /
How to slow or stop an object with no gravity
I have a space ship which gets it movement from addRelativeForce when the verticle axis is pressed. The thing I'd like it to do is slow or stop the ship when the user stops pressing the move button. Is there a way to apply a force in the opposite direction until a certain magnitude is achieved? Also there is no gravity in the scene.
function FixedUpdate(){
var moveShip = Input.GetAxis("Vertical");
var movement = new Vector3(0,moveShip + boost,0);
var currSpeed = rigidbody.velocity.magnitude;
rigidbody.AddRelativeForce(movement * speed * Time.deltaTime);
if(Input.GetKey("space") && Input.GetAxis("Vertical")){
boost = 5;
}else{
boost = 0;
}
}
Thanks
Answer by mujpir · Nov 30, 2013 at 02:49 PM
You can use rigidbody drag property to slow the spaceship . another approach is to limit velocity of spaceship if it exceeds max speed like this :
void Update()
{
if(rigidbody.velocity.magnitude>maxspeed)
{
rigidbody.velocity = rigidbody.velocity.normalized*maxspeed;
}
}
Sorry for the late response. Setting the drag works perfectly. Thanks
Answer by paulygons · Nov 30, 2013 at 06:56 PM
I seems like you're actually looking for the drag property on the rigidBody component. Set it to more than zero and your ship will start slowing down.
Your answer
Follow this Question
Related Questions
Bouncing Ball Game 3 Answers
Correcting Directional velocity for a plane 0 Answers
Gravitational pull without losing speed 1 Answer
Can I emulate simple space-like gravity? 2 Answers
Continuous Jumping using gravity 2 Answers