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 adir89457 · Feb 02, 2020 at 12:05 AM · 2drigidbody2dvelocitydash

Need help understanding advise

Hi everyone! I hope this will make sense.

I am trying to make a 2d character controller and i've already implemented basic 2d movement using "GetAxisRaw" and "rb.velocity = new Vector2 (moveInput * moveSpeed, rb.velocity.y);"

Now I am trying to add a dash feature like in Hollow Knight, and I found a great tutorial by Blackthornprod and he's doing it with "rb.velocity = Vector2.left/right * dashSpeed;". But this doesnt work for me and someone in the comments wrote "you are probably changing velocity of the rigidbody in your normal movement as well. make sure you are running this script after your movement script takes place so that this one takes control.", which I think is correct but I have no idea how to fix this. Unfortunately he's not answering so here we are.

What should I do? any help is much appreciated!

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

1 Reply

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

Answer by Magso · Feb 02, 2020 at 12:53 AM

You could use a bool with if statements.

 if(dash){
     rb.velocity = Vector2.left/right * dashSpeed;
 }
 else{
     rb.velocity = Vector2.left/right;
 }

Or set dashSpeed to an amount and have it -= by a deceleration value.

 rb.velocity = Vector2.left/right * dashSpeed;
 dashSpeed -= Time.deltaTime;
 dashSpeed = Mathf.Clamp(dashSpeed, 1, //dash amount)
Comment
Add comment · Show 5 · 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 adir89457 · Feb 02, 2020 at 02:18 AM 0
Share

Thank you for replying! But I don't see how this is related the issue. $$anonymous$$y understanding was that I used rb.velocity wrong or not in the correct order. $$anonymous$$aybe I did not understand, could you please explain more?

avatar image Magso adir89457 · Feb 02, 2020 at 10:30 AM 0
Share

"you are probably changing velocity of the rigidbody in your normal movement as well. make sure you are running this script after your movement script takes place so that this one takes control."

Basically if you have rb.velocity = ... without any if condition in update, it will execute every frame i.e. override the movement.

avatar image adir89457 · Feb 02, 2020 at 09:55 PM 0
Share

Okay I think I get it. Currently my dash is an independent function which is called with a button press. my movement is currently inside FixedUpdate. So I need to condition my movement? if so, what would that condition be? Sorry for being slow, i'm still a beginner.

avatar image Magso adir89457 · Feb 02, 2020 at 10:54 PM 0
Share

You would use a bool to set the condition like in my first example above, dash is the bool. When the dash button is pressed start a coroutine and set dash to true. Yield the amount of time the dash should be true for and then set it back to false.

$$anonymous$$y second example doesn't need a coroutine. It is constantly applying the dash speed and the value is being decreased and clamped at 1. When the dash button is pressed, simply set dashSpeed to an amount and it will be applied, decrease over time and the transition back to normal will be smoother.

avatar image adir89457 · Feb 03, 2020 at 01:46 AM 0
Share

Thank you for your help! After a lot of messing around i have finally got it working :)

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

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

Projetil rotation in straight line trajectory 2 Answers

Rigidbody2D.velocity.x not working but Y does 0 Answers

Convert Force into Velocity for 2D Player Jump 0 Answers

Player with RigidBody2D "bouncing" on EdgeCollider 0 Answers

Getting the future position of a rigidbody2D with velocity 0 Answers


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