Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 digzelot · May 20, 2014 at 02:30 AM · jumpissuedouble

How to make a proper double jump - rigidbody

I'm trying to make my double jump work consistently every time you jump..

The problem I'm having is that because of gravity, velocity.y is greater as soon as you jump than it is right before you land, and the same goes for when the character is at its zenith

for example, if jumpSpeed is 600, when I apply

Addforce(0,jumpSpeed,0);

to the beginning of the jump, the characters velocity is say 50, so if you do the double jump very fast, the character goes way high

if you do the double jump right before the character touches the ground, its like nothing happens, because velocity.y is a negative value

I tried to add

currentYVelocity = rigidbody.velocity.y

rigidbody.Addforce(0,-currentYVelocity,0)

to Addforce right before I apply the new rigidbody.addforce(0,jumpSpeed,0), but this doesn't seem to do anything

I imagine there is some complicated maths that need to be done? or perhaps something in c# that already takes care of this?

Thanks for any help

Comment
Add comment · Show 2
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 digzelot · May 20, 2014 at 03:45 AM 0
Share

Here is my current jump functionality to mitigate this variation in velocity, but its not really accurate... surely there is a proper way

in Update()

 if((jumpCount < 2 && Input.GetButtonDown("Jump")) && !bossArea) // ******* jump
         {
             if(jumpCount == 0)
             {
                 inputA = Time.time;
                 Jump ();
                 audio.PlayOneShot(jump_a);
             }
             
             if((jumpCount == 1 && Input.GetButtonDown("Jump")) && !bossArea)
                 inputB = Time.time;
             if((inputB - inputA) > 0.15f)
             {
                 Jump();
                 audio.PlayOneShot(jump_b);
             }
         }

and the function

 void Jump() 
     {
         if(!isInCloud) // ********* $$anonymous$$aking sure jumping is consistent
         {
 
             rigidbody.AddForce(0,-currentYVelocity,0);
             isGrounded = false;
 
             if(jumpCount == 0)
             {
                 rigidbody.AddForce(0,jumpSpeed,0);
                 ++jumpCount;
             }
 
             if(((inputB - inputA) > 0.15f) && ((inputB - inputA) < 0.2f))
             {
                 rigidbody.AddForce(0,jumpSpeed - 500,0);
                 ++jumpCount;
             }
 
             if(((inputB - inputA) > 0.2f) && ((inputB - inputA) < 0.4f))
             {
                 rigidbody.AddForce(0,jumpSpeed - 400,0);
                 ++jumpCount;
             }
 
             if(((inputB - inputA) > 0.4f) && ((inputB - inputA) < 0.5f))
             {
                 rigidbody.AddForce(0,jumpSpeed + 100,0);
                 ++jumpCount;
             }
 
             if(((inputB - inputA) > 0.5f) && ((inputB - inputA) < 0.6f))
             {
                 rigidbody.AddForce(0,jumpSpeed + 300,0);
                 ++jumpCount;
             }
 
             if(((inputB - inputA) > 0.6f) && ((inputB - inputA) < 0.7f))
             {
                 rigidbody.AddForce(0,jumpSpeed + 500,0);
                 ++jumpCount;
             }
 
             if(((inputB - inputA) > 0.7f) && ((inputB - inputA) < 0.8f))
             {
                 rigidbody.AddForce(0,jumpSpeed + 900,0);
                 ++jumpCount;
             }
 
             if(((inputB - inputA) > 0.8f) && ((inputB - inputA) < 1f))
             {
                 rigidbody.AddForce(0,jumpSpeed + 1300,0);
                 ++jumpCount;
             }
 
             if((inputB - inputA) > 1)
             {
                 rigidbody.AddForce(0,jumpSpeed + 1500,0);
                 ++jumpCount;
             }
         }
avatar image digzelot · May 20, 2014 at 03:56 AM 0
Share

The idea is that the double jump for a side scroller should not deviate - the jump should always have the same amount of force, that way if the player needs to make a split second decision, they are not penalized because of gravity. Hope this makes sense : )

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by digzelot · May 20, 2014 at 06:15 AM

I simply overlooked the obvious... for anyone with a similar issue, do not use Addforce .... simply change velocity directly.

The above work less effectively than this

 void Jump() 
     {
         rigidbody.velocity = new Vector3(0, 30, 0);
         jumpCount++;
         isGrounded = false;
     }
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 Random_Deslime · Jun 25, 2018 at 12:26 PM 0
Share

It still has the exact same problem...

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

21 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

Related Questions

i'dont want double Jump 1 Answer

Player Jump via Transform on Input Space 2 Answers

Character Controller Jumping Higher against Box Collider 0 Answers

Jumping Issue, Need Help. 0 Answers

How Can I Make My Character Double Jump and Wall Jump? 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