Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by EdjofGlory · Jul 26, 2019 at 06:07 PM · 3dfpscharactercontrollerdash

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;
         }
     }
 }



Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

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;
      }
Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image EdjofGlory · Jul 27, 2019 at 08:09 AM 0
Share

Sorry, Im a bit confused but is it the same as what I did on the if statement?

avatar image xxmariofer EdjofGlory · Jul 27, 2019 at 11:00 AM 1
Share

Tes, your code gets triggered only once (when Burton is clicked) thats why is telepirting

avatar image EdjofGlory xxmariofer · Jul 27, 2019 at 04:05 PM 0
Share

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;
         }


Show more comments
avatar image
1

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;
         }
     }
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kaiser_V · Jun 08, 2020 at 02:25 AM 0
Share

can I use your code for my game?

avatar image FarleyClimber · Aug 26, 2020 at 04:14 AM 0
Share

Your code is brilliant, I learned a lot from it, thank you

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

193 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges