Why does this code still allows me to move the player around?
Hi, I'm trying to understand how this code still allows me to move my Player around the scene.
public Rigidbody rb;
public float acceleration = 500f;
public UnityEngine.ForceMode forceMode = ForceMode.Impulse;
void Update() {
rb.AddRelativeForce(new Vector3(Input.GetAxis("Horizontal") * acceleration * Time.deltaTime, 0, Input.GetAxis("Vertical") * acceleration * Time.deltaTime), forceMode);
rb.velocity = Vector3.zero;
}
Shouldn't setting the velocity to 0 after applying the force prevent me from moving? Or are these not actually run in the order they appear in my code?
This is basically a test, because I want to understand how this works. My goal is to have my character movement be really snappy, while still using forces. Right now, whatever I tried, my player is still sliding a little bit after I stop pressing a movement key.
If I really can't do it, I'll try using the built in character movement controller.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612214948im_/https://answers.unity.com/themes/thub/images/avi.jpg)