Question by
goodgamershow · Apr 09, 2021 at 09:11 AM ·
c#scripting problemunity 2daddforce
How to make AddForce dash smoother, instead of teleporting
Right now I have a code for player dashing when I press the button "M".
public Rigidbody2D rb;
public float runSpeed = 5f;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update(){
if(Input.GetKeyDown(KeyCode.M){
rb.AddForce(transform.right * (runSpeed * 1000f), ForceMode2D.Force);
}
}
The problem is when player dashes, it almost looks like teleporting - he instantly appears in the dash direction, instead of fastly moving. I tried using ForceMode2D.Impulse, but then player doesn't dash at all. Would be great, if you could help me. Thanks
Comment