Question by
RioAraki · May 11, 2016 at 02:27 PM ·
movementtutorialspace shooterinertia
Space shooter tutorial, space ship keep moving and has interia
I just follow the tut and make my space ship move. However, it seems like the ship has a strong inertia and keeps moving even I release the move key. I hope my ship could stop as long as I release the move key. I am wondering why is it happening since I just follow the tut and get a different result. Here is my code:
public class GameController : MonoBehaviour {
private Rigidbody rb;
public float speed;
void Start() {
rb = GetComponent<Rigidbody>();
}
void FixedUpdate() {
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
}
Comment
Best Answer
Answer by dCalle · Jun 08, 2016 at 09:27 PM
don't use AddForce. Use velocity. Or if you want to stick with the accelerating, write another if that checks for no given Input and then set rb.velocity to 0 ;-)
Your answer
![](https://koobas.hobune.stream/wayback/20220612080535im_/https://answers.unity.com/themes/thub/images/avi.jpg)