Hello, I have a dashing script that allows you to dash based on your input (I.e. W + D is forward right). Now, as i stated in my question, The dashing seems to stop whenever I let go of wasd.
Here are the codes that are important to the dash:
private void Update()
{
float horizontal = Input.GetAxisRaw("Horizontal");
float vertical = Input.GetAxisRaw("Vertical");
Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
float targetangle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
target = Quaternion.Euler(0f, targetangle, 0f);
if (Input.GetKey(KeyCode.Q) && candash)
{
StartCoroutine(Dash(dashtime, dashcd));
}
if (isdashing)
{
dashspeed = Mathf.Lerp(dashspeed, enddashspd, dashrate);
cc.Move(_dashDirection * dashspeed * Time.deltaTime);
}
}
IEnumerator Dash(float s, float cd)
{
isdashing = true;
candash = false;
_dashDirection = target * Vector3.forward;
yield return new WaitForSeconds(s);
isdashing = false;
dashspeed = initialdashspeed;
yield return new WaitForSeconds(cd - s);
candash = true;
}
The thing i used for the player is a charactercontroller (as shown by the “cc” in the script). Im aware that the problem is that im using input.getaxis but my main problem is how can i fix/change the code to make it so that, Whenever I press the dash button, I still dash in the desired direction i wanted to go in even if i let go of the WASD keys.