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 treese_ · Nov 14, 2019 at 01:41 PM · 3dfallingdouble jumpconstant force

Trouble with Double Jumping Under a Constant Force

So I have a player character that is capable of double jumping, which is achieved through the rb.AddForce command. I also have a constant force placed on the character so they fall to the ground faster. the double jump code works fine if used when the player is on the way up or at the peak of their first jump. The issue is, if my character starts moving down, the double jump force adds with the much stronger constant force to effectively nullify it, which isn't good.

What I want is either a way to increase the fall speed of the character without a constant force or disable/weaken the constant force very briefly to allow the double jump to work properly before resetting it so thew player isn't so floaty. Any suggestions?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Philosophbot · Nov 14, 2019 at 01:56 PM

Well, there are a couple of things you can do. Unity engine has a built-in gravity system for the rigid-body component if you want to use that(it would probably act similar to your constant force. Although I think the best way to fix your problem would be to add more force to your jumps. Maybe you could have it so that every time the player jumps you apply the JumpForce + (the constant force at that moment) to nullify the effect of the constant force on the jump.

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 treese_ · Nov 15, 2019 at 12:49 PM 0
Share

The issue with that is that the double jump on the upward arc would become super strong (as the applied force of the double jump combines with the force of the first jump(for example, if Jump1 force is 4 and Jump2 force is like 15, the 15 combines with the 4 to create a monstrously powerful jump) ), while on the way down to the ground it would be weaker, since it's being subtracted from by the downward constant force. I'm trying to find a way to keep the double jump consistent in power whether it's going up or down while keeping a fast and realistic falling speed.

EDIT: Where might I find this gravity option?

avatar image Philosophbot treese_ · Nov 15, 2019 at 03:28 PM 0
Share

To fix this problem of the super jump on the upward arc, you could use an if statement that checks to see if the character is falling. The easiest way to do this would probably be to find the velocity of the Rigidbody. Unity engine has an easy way to check this in the form of Rigidbody.velocity which will return a Vector3 with the different velocities for x,y,z.

You could say If(rb.velocity.Y < 0) // do jump with cancel force this works because if an object has a negative y velocity, you know that the object is falling.

In terms of the gravity option, the Rigidbody component has a checkbox for gravity in the editor window: alt text

Here is the link to the Unity Rigidbody manual for more information: https://docs.unity3d.com/$$anonymous$$anual/class-Rigidbody.html

avatar image treese_ Philosophbot · Nov 18, 2019 at 01:06 PM 0
Share

I did find the gravity option, which gave my character a much more natural fall speed, thanks. I was wondering, would there potentially be a way to set the rigidbody's vertical movement to zero, then immediately add in the double jump? That way, it is always the same regardless of previous direction of movement.

Show more comments
avatar image
0

Answer by Spiritdon · Apr 16, 2021 at 09:38 PM

All you really need to do is cancel the force of acceleration

if (Input.GetKeyDown(KeyCode.Space)&& extraJumpCounter != 0)//allow the player to jump as long asthey are pressing space and they have extra jumps

     {
         StartCoroutine(JumpParticle()); //Play Particle effect
         extraJumpCounter--;
         float forceOfAcceleration =Mathf.Abs(rb.mass*Physics.gravity.y);//the force of acceleration 
         if (IsFalling())//canceling out the Force of Gravity for mroe effective double jumping
         {
             float tempForce = jumpForce + forceOfAcceleration;
             rb.AddForce(new Vector3(0, tempForce, 0), ForceMode.Impulse);
         }
         else
         {
             rb.AddForce(new Vector3(0, jumpForce, 0), ForceMode.Impulse);
         }
     }
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

150 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

Related Questions

Is there any way to do a double jump with the first person controller? 2 Answers

Imported Mesh falls through floor. Cannot use RigidBodies or Mesh Colliders 1 Answer

Double jump code 0 Answers

How to double jump 1 Answer

How Do I Stop My Character From Falling Through The Terrain!? 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