Implementing A Dash With My CharacterController

I’m developing a 3D fighter game with my friends currently and currently we have a movement system where the player will constantly face the enemy. With the transform.TransformPosition() function they essentially orbit around the enemy, when the A key is pressed it will move to the left, however since the transform.TransformPosition() and constant rotation towards the enemy, it will move in a circle. This is exactly what we wanted. But the question is, how would we implement a dash key with the Q and E keys? I attempted to have a system work similar to the basic controls, having a Vector3 just for movement regarding the dash keys and translating it with TransformPosition(), but it didn’t work out very well.

Here’s my movement script

using UnityEngine;
using System.Collections;

public class CharController : MonoBehaviour {

    //Created: August 21-28, 2015
    //Creator: SwaggyMcChicken
    //Purpose: Enables player to move, "orbitting" the enemy
   
    //Edited: September 2, 2015
    //Editor: SwaggyMcChicken
    //Purpose: Implementing a "Dash" feature

    public CharacterController CC;
   
    //Reguarding Movement section
    public float JumpHeight = 0f;
    public float Speed = 6f;
    public float Gravity = 5f;
    public float DashSpeed = 10f;
    bool Dashing = false;
    Vector3 MoveDirection;
    Vector3 DashDirection;


    void Update () {

        if(CC.isGrounded == true){

            //Gets player input based on Axis (WASD)
            MoveDirection = new Vector3 (Input.GetAxis ("Horizontal"), Input.GetAxis("Jump"), Input.GetAxis ("Vertical"));
               
            //Translating from local cords
            MoveDirection = transform.TransformDirection (MoveDirection);
               
            //Multiplying to add Speed variable
            MoveDirection *= Speed;

            //If let dash key is pressed & player isn't currently dashing, change Vector3
            if(Input.GetKey(KeyCode.E) && Dashing == false){
               
                DashDirection.x = DashDirection.x + DashSpeed;
                Dashing = true;
                   
            }

            //Same as above, but to the right.
            if(Input.GetKey(KeyCode.Q) && Dashing == false){

                DashDirection.x = DashDirection.x - DashSpeed;
                Dashing = true;

            }

            //Translating from local cords
            DashDirection = transform.TransformDirection(DashDirection);
           
        }       
       
    }
   
    void FixedUpdate(){
       
       
        if (CC.isGrounded == false) {
           
            //Simulating Gravity and syncs with current deltaTime
            MoveDirection.y -= Gravity * Time.deltaTime;
           
            if (MoveDirection.y > 50) {
               
                MoveDirection.y = 50;
                Debug.Log (MoveDirection.y);
               
            }

        }

        //Moves character
        CC.Move(MoveDirection * Time.deltaTime);

        //If player is dashing, use Vector3 to dash and set Dashing to false
        if (Dashing == true) {

            CC.Move (DashDirection * Time.deltaTime);
            Dashing = false;

        }
   
    }

}

I could be overlooking this entirely. I do it often lol. Any help would be appreciated

I’ve been experimenting with multiple solutions, nothing has worked.

I usually have a float for startSpeed, one for speed. In start I set speed=startSpeed. Whenever the player dash’s I set speed to x*speed. When the let go of the dash button I set speed=startSpeed again.
Don’t know if that helps you in your case

Where do you start with this? I’m curious where you did that.

I don’t have access to my old scripts (on mobile atm) but from memory I had something like this in the player movement script. declare the 2 floats with a value applied to startSpeed.
in Void Start() have speed =startSpeed;

In movement have something like:
If(input <‘whatever you are using for movement’>){
your normal movement stuff here (e.g moveDirection *=speed;)
}

If (input <'movement input & dash input>){
speed *= whatever your dash multiplier is (or just add extra speed, or however you want)
}
Else speed = startSpeed;

When I said dash I should have been a little more precise lol, I meant a dash, roll, or something like that, lol. This seems to be a sprinting function

Ah, ok. Sorry my mistake (i did wonder why it seemed so complicated). I’ve never used rolls but will keep my eye on this so I can find out how for when I do.

Lol I’ll let you know if I figure it out

Still looking for any tips and suggestions, been searching for some.

Here’s my not so clean code but it works. Hope this helps!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float speed = 10f;
    public float dashLength = 0.15f;
    public float dashSpeed = 100f;
    public float dashResetTime = 1f;

    public CharacterController characterController;

    private Vector3 dashMove;
    private float dashing = 0f;
    private float dashingTime = 0f;
    private bool canDash = true;
    private bool dashingNow = false;
    private bool dashReset = true;

    void Update()
    {
        float moveX = Input.GetAxis(“Horizontal”);
        float moveZ = Input.GetAxis(“Vertical”);

        Vector3 move = transform.right * moveX + transform.forward * moveZ;

        if (move.magnitude > 1)
        {
            move = move.normalized;
        }


        if (Input.GetButtonDown("Dash") == true && dashing < dashLength && dashingTime < dashResetTime && dashReset == true && canDash == true)
        {
            dashMove = move;
            canDash = false;
            dashReset = false;
            dashingNow = true;
        }

        if (dashingNow == true && dashing < dashLength)
        {
            characterController.Move(dashMove * dashSpeed * Time.deltaTime);
            dashing += Time.deltaTime;
        }

        if (dashing >= dashLength)
        {
            dashingNow = false;
        }

        if (dashingNow == false)
        {
            characterController.Move(move * speed * Time.deltaTime);
        }

        if (dashReset == false)
        {
            dashingTime += Time.deltaTime;
        }

        if (characterController.isGrounded && canDash == false && dashing >= dashLength)
        {
            canDash = true;
            dashing = 0f;
        }

        if (dashingTime >= dashResetTime && dashReset == false)
        {
            dashReset = true;
            dashingTime = 0f;
        }
    }
}