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 Core_9th · May 11, 2020 at 06:52 PM · movementplayerdashdiagonal

Cannot dash in left-down, left-up and right-down directions?

Alright, this is pretty much the first project I actually want to finish after a lot of my past attempts and I've been trying to fix this stupid bug. So basically I have a dash function on my player that allows you to dash when pressing space/jump and the dash works by multiplying the movement factor by an amount for the player to move faster. After you activate the dash you can move in every direction with no problems, but if you try to activate the dash while moving in the down-left, up-left or the down-right directions it doesn't work, but up-right does. I'm guessing it's because of the player moving in a negative direction but if that were the case it wouldn't work when moving straight left or down either. Any help would be appreciated as I do not understand why this won't work as intended. Thanks! This is the code for the movement: using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class PlayerMovement : MonoBehaviour
 {
     // Start is called before the first frame update
     public float speed = 4f;
     public float dashMult = 2f;
     private float initialDashMult;
     public float initialDashCooldown = 1f;
     private float dashCooldown;
     private float dashStopTime;
 
     Rigidbody2D body;
 
     float horizontal;
     float vertical;
 
     private void Start()
     {
         body = GetComponent<Rigidbody2D>();
         initialDashMult = dashMult;
         dashMult = 1f;
     }
 
     // Update is called once per frame
 
     void Update()
     {
 
         horizontal = Input.GetAxisRaw("Horizontal");
         vertical = Input.GetAxisRaw("Vertical");
 
         if (dashCooldown > 0)
         {
             dashCooldown -= Time.deltaTime;
             dashStopTime = initialDashCooldown - .2f;
             if(dashCooldown > dashStopTime)
             {
                 dashMult = initialDashMult;
             }
             else
             {
                 dashMult = 1f;
             }
         }
         //dash using space
         if (Input.GetButton("Jump") && dashCooldown < .00001)
         {
             //start dash
             dashCooldown = initialDashCooldown;
         }
     }
     void FixedUpdate()
     {
         //movement
         body.velocity = new Vector2(horizontal * speed * dashMult, vertical * speed * dashMult);
     }
 }
 
Comment
Add comment · Show 3
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 darksider2000 · May 11, 2020 at 08:53 PM 0
Share

Your problem is not in the code you gave us, I ran your code and the dash worked in all 8 directions. The problem is either in another script conflicting with this one (Do you have any other scripts that access the same rigidbody), or in the input (Try changing keys for the axes).

avatar image Core_9th darksider2000 · May 12, 2020 at 05:17 AM 0
Share

To answer your solutions, there's not another script that accesses the same rigidbody and I tried dashing diagonally using WASD which surprisingly worked. (I tested using arrow keys before) Well seeing as you said that dashing is working for you I assume that it's my keyboard's fault, but at the same time it works for up-right so why shouldn't it work for the other ones? I suppose you tried using the WASD keys and concluded that it works. If you have time can you please try to also dash diagonally using the arrow keys if you didn't already? I want to know if it's my keyboard's fault or not. Anyway, thanks for the help, much appreciated!

avatar image Core_9th Core_9th · May 12, 2020 at 05:26 AM 0
Share

Alright I figured it out; it turns out my keyboard is kinda broken, I have a 2-key ghosting if I try to use the arrow keys. Welp that's that. Thanks for letting me know and don't worry about this question anymore.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Core_9th · May 12, 2020 at 05:29 AM

Alright I figured it out; it turns out my keyboard is kinda broken, I have a 2-key ghosting if I try to use the arrow keys. Welp that's that. Anyone encountering this problem make sure you don't have ghosting on your keyboard; you can try every key for free here on this site: https://drakeirving.github.io/MultiKeyDisplay/ Have a good day to anyone finding this!

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 DrewDunne · May 12, 2020 at 09:44 PM 0
Share

Wow what an unexpected answer. Glad you figured it out though!

avatar image
1

Answer by DrewDunne · May 11, 2020 at 08:13 PM

So, I've gathered that initialDashCooldown is the "Cooldown" time for Dashing. But what is the difference between dashMult and initialDashMult? Does the dash decay over time? Perhaps more importantly, it seems you may have an issue with dashStopTime... it seems that it's value is simply 1.8f, which you are reassigning every frame via Line 34. If it's meant to have a constant value, I suppose that's fine but currently you are performing arithmetic every frame to yield a constant value.

It might be worth taking a look at those variables to see if there's something unintended occuring in your Update sequence that could be having the consequences you are seeing. If you can't find anything, it might be worth explaining what these variables are supposed to do and/or give more detail on how dash should function (for instance, does it decay or not). What is 'dashMult', etc.

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 Core_9th · May 12, 2020 at 05:05 AM 0
Share

Alright so I looked in the code just now and I can say this: 1. dash$$anonymous$$ult is a variable always multiplied to player speed and it can either be: 1 or initialDash$$anonymous$$ult (it's the value that dash$$anonymous$$ult gets set to when the player is dashing so the player is actually faster when dashing)

2.yeah I put dashStopTime there and it's bad so I should probably move it to start to avoid making a lot of operations for the same answer, that's what you intended to say right? Thanks for pointing it out!

avatar image Core_9th · May 12, 2020 at 05:26 AM 0
Share

Alright I figured it out; it turns out my keyboard is kinda broken, I have a 2-key ghosting if I try to use the arrow keys. Welp that's that. Thanks for letting me know and don't worry about this question anymore.

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

212 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Ghost Trail - Creating Sequence of Images that move on players position 0 Answers

,I am trying to code a dash in c#. I cant get it, help! 1 Answer

Dash in movement direction, not in forward direction 0 Answers

Disable diagonal movement in unity 2D 1 Answer

How to make a good PlayerMovement 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