• 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 cauevt · Aug 19, 2018 at 10:31 PM · movementcontrollermovement scriptplayer movementdash

Help with my Dash move?

Hi, guys. I'm trynig to code a player controller with a Dash function that allows my character to dash from a point to another, by using the "Dash" button that i set at the Input Manager (left shift). I've watched 5 ou 6 YouTube tutorials and none have worked for me.

I did tried some answers here in the Unity Answer section, but i've concluded that something is wrong with my code.

Could someone please help me?

 public class PlayerController : MonoBehaviour {
 
 
     public float speed;
     public float jumpForce;
     public float secondJumpForce;
     private float moveInput;
 
     private Rigidbody2D rb;
 
     private bool facingRight = true;
 
     private bool isGrounded;
     public Transform groundCheck;
     public float checkRadius;
     public LayerMask whatIsGround;
 
     private int extraJump;
     public int extraJumpValue;
     
     //Dash tentative
     public float startDashTime;
     float dashTime;
     public float dashSpeed;
     public Input dash;
 
     // Use this for initialization
     void Start () {
         rb = GetComponent<Rigidbody2D>();
         extraJump = extraJumpValue;
         dashTime = startDashTime;
     }
 
 
     private void FixedUpdate()
     {
 
         isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
 
         moveInput = Input.GetAxis("Horizontal");
         rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
         
 
         if (facingRight == false && moveInput > 0)
         {
             Flip();
         }
         else if(facingRight == true && moveInput < 0)
         {
             Flip();
         }
 
 
         
 
     }
 
     // Update is called once per frame
     void Update ()
     {
         if (isGrounded == true)
         {
             extraJump = extraJumpValue;
         }
         Jumping();
         Dash();
         /*
          * "Blink" system, used while dash does not work
          * if (Input.GetKeyDown(KeyCode.Z))
         {
             transform.position += new Vector3(dashSpeed * Time.deltaTime, 0.1f,0f);
         }
         */
     }
 
     private void Jumping()
     {
         if (Input.GetButtonDown("Jump") && extraJump > 0)
         {
             rb.velocity = Vector2.up * secondJumpForce;
             extraJump--;
         }
         if (Input.GetButtonDown("Jump") && extraJump == 0 && isGrounded == true)
         {
             rb.velocity = Vector2.up * jumpForce;
         }
     }
 
     void Flip()
     {
         facingRight = !facingRight;
         Vector3 Scaler = transform.localScale;
         Scaler.x *= -1;
         transform.localScale = Scaler;
     }
 
     void Dash()
     {
         if (Input.GetButton("Dash"))
         {
             rb.velocity = Vector2.right * dashSpeed;
             
         }
     }
 }
Comment
Add comment · Show 1
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 Trevdevs · Aug 19, 2018 at 10:41 PM 0
Share

It would be helpful to tell us what is happening that you don't want. Is the player not moving the direction you want? Is the player not moving at all? tell us what is happening

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by myzzie · Aug 20, 2018 at 05:11 AM

I think what you're looking for is

 rb.velocity = transform.right * dashSpeed

Comment
Add comment · Show 1 · 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 cauevt · Aug 20, 2018 at 03:51 PM 0
Share

Well, thanks hahaha. $$anonymous$$y bad.

Also, i was doing it in Update ins$$anonymous$$d of FixedUpdate.

It works now :)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

147 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Dash in movement direction, not in forward direction 0 Answers

Non slippery movement 1 Answer

Move Object a direction with one button and move the object back with the same button? 1 Answer

How to make basic touch screen controls 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