I have started to create a dashing system so the player can dash left, right, and backwards. I have it so when the user double taps the A,S, and D button they will move over. Is there anyway to smooth the movement? I am also having an issue with the “isDashing” bool, it doesn’t seem to be updating for some reason. Here is my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Dashing : MonoBehaviour {
public float tapSpeed = 0.5f; //in seconds
public float dashSpeed = 50;
public float waitTime = 5f; //in seconds
public bool isDashing;
private float lastTapTime = 0;
// Use this for initialization
void Start()
{
lastTapTime = 0;
isDashing = false;
StartCoroutine(WaitTime());
}
// Wait time after dashing
public IEnumerator WaitTime()
{
yield return new WaitForSeconds(waitTime);
isDashing = false;
}
// Update is called once per frame
void Update()
{
if (isDashing == false)
{
if (Input.GetKeyDown(KeyCode.A))
{
if ((Time.time - lastTapTime) < tapSpeed) //double tap
{
isDashing = true;
transform.Translate(Vector3.left * dashSpeed * Time.deltaTime);
Debug.Log("Dash left");
}
lastTapTime = Time.time;
}
if (Input.GetKeyDown(KeyCode.D))
{
if ((Time.time - lastTapTime) < tapSpeed) //double tap
{
isDashing = true;
transform.Translate(Vector3.right * dashSpeed * Time.deltaTime);
Debug.Log("Dash right");
}
lastTapTime = Time.time;
}
if (Input.GetKeyDown(KeyCode.S))
{
if ((Time.time - lastTapTime) < tapSpeed) //double tap
{
isDashing = true;
transform.Translate(Vector3.back * dashSpeed * Time.deltaTime);
Debug.Log("Dash back");
}
lastTapTime = Time.time;
}
}
if(isDashing == true)
{
WaitTime();
}
}
}