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 /
  • Help Room /
avatar image
0
Question by Jayrab · Mar 18, 2018 at 07:14 PM · 2d-platformerjumpdouble jump

Double jump feels really off

Hi there

Pretty new to Unity. I'm messing around, trying to make a simple 2D platformer.

I managed to implement basic movement and jumping. My next challenge was to create a double jump. It "works" but feels really off. Basically what happens is that the later I press the jump button again, the less I actually jump. So as I'm falling down, I barely get propelled up anymore, if at all. So basically, double jumping only really has an effect at the beginning of a jump. And even then, the result varies. I want the effect of the jump to be constant and not to be dependant on my current jump arch.

Here's the code that is relevant to moving and jumping. Note: A lot of the code stems from this video right here.

     int count = 0;
     public Text countText;
     public Text winText;
 
 
     float maxSpeed = 10f;
     public float jumpForce = 70f;
 
     bool isFacingRight = true;
     private Rigidbody2D rb;
 
     bool grounded = false;
     public bool doubleJump = false;
     public Transform groundCheck;
     float groundRadius = 0.2f;
     public LayerMask whatIsGround;
     Animator anim;
 
     // Use this for initialization
     void Start ()
     {
         rb = GetComponent<Rigidbody2D>();
         anim = GetComponent<Animator>();
         winText.text = "";
     }
     
     // Update is called once per frame
     void Update ()
     {
         if ((grounded || !doubleJump) && Input.GetButtonDown("Jump"))
         {
             anim.SetBool("grounded", false);
             rb.velocity.Set(rb.velocity.x, 0);
             
             rb.AddForce(new Vector2(0, jumpForce));
 
             if (!doubleJump && !grounded) doubleJump = true;
         }
 
     }
 
     void FixedUpdate()
     {
         grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
         anim.SetBool("grounded", grounded);
         if (grounded) doubleJump = false;
 
         float move = Input.GetAxis("Horizontal");
         anim.SetFloat("Speed", Mathf.Abs(move));
         rb.velocity = new Vector2(move * maxSpeed, rb.velocity.y);
 
         if ((move > 0 && !isFacingRight) || move < 0 && isFacingRight) Flip();
     }

Is there any way I can improve my double jump so that it feels more like in other games and isn't affected by how fast down I'm currently going? (i thought rb.velocity.Set(rb.velocity.x, 0); would fis this but apparently not..)

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

Answer by Jayrab · Mar 19, 2018 at 06:23 PM

So, I found out what the problem was. I replaced

 rb.velocity.Set(rb.velocity.x, 0);

with

 rb.velocity = new Vector2(rb.velocity.x, 0);

And now the double jump isn't affected by my fall.

Comment
Add comment · 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

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

79 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

Related Questions

Problem with Jumping code in Unity 2D,problem with Jumping code in Unity 2D 0 Answers

how do i add double jumping into my 2d prefab character controlle 0 Answers

Why only the first frame plays in my jump animation 0 Answers

Error: An object reference is required to access non-static member, help? 2 Answers

How do I disable Jumping while on my JumpPad? 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