- Home /
 
Smoother dash with a Character Controller
How do you do a smoother dash with a character controller?
I tried adding a lerp but it does not make any sense, hence I had to remove it.
My current dash without a lerp looks like a teleport:
     void Dash()
     {
         if (time_to_dash <= 0)
         {
             /*if (Input.GetKeyDown(KeyCode.E)&&Input.GetKeyDown(KeyCode.S))
             {
                 DashDirection = new Vector3(BDashPos.localPosition.x, BDashPos.localPosition.y, BDashPos.localPosition.z);
                 DashDirection = transform.TransformDirection(DashDirection);
                 DashDirection *= dashSpeed * Time.deltaTime;
                 character_controller.Move(DashDirection);
                 time_to_dash = startDash;
 
             }*/
                 if (Input.GetKeyDown(KeyCode.E))
             {
 
 
                 
                 DashDirection = new Vector3(Input.GetAxis("Horizontal")*10f, DashPos.localPosition.y, Input.GetAxis("Vertical") * 10f);
                 DashDirection = transform.TransformDirection(DashDirection);
                 //DashDirection *= dashSpeed * Time.deltaTime;
                 character_controller.Move(DashDirection);
                 time_to_dash = startDash;
                 
             }
 
             
 
         }
 
         else
         {
             time_to_dash -= Time.deltaTime;
         }
     }
 }
 
              Answer by xxmariofer · Jul 26, 2019 at 07:37 PM
move character_controller.Move(DashDirection); you will need to reduce tge speed to the else
      else
      {
          character_controller.Move(DashDirection);
          time_to_dash -= Time.deltaTime;
      }
 
              Sorry, Im a bit confused but is it the same as what I did on the if statement?
Tes, your code gets triggered only once (when Burton is clicked) thats why is telepirting
It works (barely), I adjusted the DashDirection and divided it with my gravity Variable on the else but it has that "slippery" effect, that makes it look like a slide than a dash. You have any hints how to solve this? Thanks for the help btw.
  if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.E))
             {
 
 
                 
                 DashDirection = new Vector3(Input.GetAxis("Horizontal")*5f, DashPos.localPosition.y, Input.GetAxis("Vertical") * 5f);
                 DashDirection = transform.TransformDirection(DashDirection);
                 //DashDirection *= dashSpeed * Time.deltaTime;
                 character_controller.$$anonymous$$ove(DashDirection);
                 time_to_dash = startDash;
                 
             }
 
             
 
         }
 
         else
         {
             character_controller.$$anonymous$$ove(DashDirection/gravity);
             time_to_dash -= Time.deltaTime;
         }
                   Answer by BraydenB · Apr 05, 2020 at 03:30 AM
Here's my not so clean code but it works @EdjofGlory
 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;
         }
     }
 }
 
              Your code is brilliant, I learned a lot from it, thank you
Your answer
 
             Follow this Question
Related Questions
How to make my Character run through walls with the use of the Character Controller component 1 Answer
First person dash advice 0 Answers
What is the best way to move a character for an FPS? 1 Answer
3D character mesh ignoring transform values and rotating without the rig 0 Answers
Enemy Will not die 1 Answer