Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 brbunity · Apr 24, 2021 at 10:33 AM · jumpreset

Why doesn't my jump reset?

public Vector2 jump; public float jumpForce = 2.0f;

 float horizontal;
 float vertical;
 Rigidbody2D rb;
 IEnumerator dashCoroutine;
 public bool isGrounded;

 bool isDashing;
 bool canDash = true;
 float direction = 1;
 float normalGravity;

 void Start()
 {
     rb = GetComponent<Rigidbody2D>();
     normalGravity = rb.gravityScale;
     jump = new Vector2(0.0f, 4.0f);
 }

 void Update()
 {
     if (horizontal != 0)
     {
         direction = horizontal;
     }
     horizontal = Input.GetAxisRaw("Horizontal");
     vertical = Input.GetAxis("Jump");
     if (Input.GetKeyDown(KeyCode.LeftShift))
     {
         if (dashCoroutine != null)
         {
             StopCoroutine(dashCoroutine);
         }
         dashCoroutine = Dash(.1f, 1);
         StartCoroutine(dashCoroutine);
     }
 }

 void OnCollisionStay()
 {
     isGrounded = true;
 }

 private void FixedUpdate()
 {
     rb.AddForce(new Vector2(horizontal * 20, 0));

     if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
     {
         rb.AddForce(jump * jumpForce, ForceMode2D.Impulse);
         isGrounded = false;
     }
     if (isDashing)
     {
         rb.AddForce(new Vector2(direction * 10, 0), ForceMode2D.Impulse);
     }
 }

 IEnumerator Dash(float dashDuration, float dashCooldown)
 {
     isDashing = true;
     canDash = false;
     rb.gravityScale = 0;
     rb.velocity = Vector2.zero;
     yield return new WaitForSeconds(dashDuration);
     isDashing = false;
     rb.gravityScale = normalGravity;
     rb.velocity = Vector2.zero;
     yield return new WaitForSeconds(dashCooldown);
     canDash = true;
 }
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 HellsHand · Apr 24, 2021 at 02:58 PM

Chances are judging by the fact your are using a RigidBody2D you have 2D colliders. In that case you want to use OnCollisionStay2D as opposed to OnCollisionStay.

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 brbunity · Apr 24, 2021 at 04:54 PM 0
Share

Thanks it's all working 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.

Follow this Question

Answers Answers and Comments

116 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

Related Questions

Jumps never reset 2 Answers

Scenes keep resetting, why? 2 Answers

how do i make this to a negative (ShopRespawn < 180)? 1 Answer

reset timer using a GUI button 2 Answers

Reset the countdown timer 2 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