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 GameTime45 · Apr 07, 2015 at 01:34 AM · unity 2djumpexponential

Exponential Increase/Decrease jump

Been trying to make a jump that will almost "hang" in the air. Where the jump will slow down as it reaches the apex of the arch before gravity pulls it down as it regularly does.

Currently I'm using this...

 rigidbody2D.AddForce(new Vector2(0, 10)

But it will just add a set force which will be decreased at the same rate by the gravity value. It won't give me the "hang" I'm looking for.

Is there a way to make that "AddForce" value exponential where as the vertical force gets closer to 0 the rate at which it decreases will slow down? Any pointers would be appreciated!

Comment
Add comment · Show 1
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 DoTA_KAMIKADzE · Apr 08, 2015 at 12:57 AM 0
Share

You can change your velocity manually.

You can configure gravity value.

You can adjust forces manually when your height vector (Y probably) gets closer to the ground height (Y probably) value.

You can do all of the above^.

It's pretty much up to you.

3 Replies

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

Answer by toddisarockstar · Apr 08, 2015 at 03:33 AM

if you need something special its simple enough to turn of the characters gravity in the inpectors rigidbody component and just script it yourself. just got to be creative thats all.

simple up and down code might be

 var myweight:float=.01;
 var legstrength:float=1;
 var myweightafterjump:float=.005;
 var spot:float;
 var groundlevel:float;
 var jumping:boolean;    //----------make this true to jump!! 
 groundlevel=transform.postion.y;
 
 
 function Update (){
 
 if(jumping==false){spot=legstrength;}
 
 if(jumping==true){
 if (spot>0){spot=spot-myweight;}else{spot=spot-myweightafterjump;}
 transform.position.y=transform.position.y+spot;
 }
 
 if(transform.position.y<groundlevel){jumping=false;transform.position.y=groundlevel;}
 
 

 

i didnt test this so you got to debug and play with the numbers at the top. but to get you started. basically slowly taking away from a number that is added to the y position creates a smooth arch instead of a jagged down movement if you directly assign y. i put another variable in there so you can make the down movement a little slower so it looks like he hangs a bit.

you pry want to replace the "ground level" part with an OnCollision Detection.

if you want to get more control, multiplying things with "distance to start". can also make a jump soothly go faster as it goes higher like a rocket or slower as it reaches ground like a hovercraft or really whatever you want something to do can be done with a simple math. Unfortunatly, they dont tell you all stuff this in the tutorials!

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

Answer by zardini123 · Apr 08, 2015 at 03:08 AM

Using forces in this situation is something you shouldn't do.

The general way of doing basic jumping in any 3D or 2D game using a rigid body to control such character, is to directly modify the y axis of the velocity of the rigid body when its grounded, like so:

 Vector3 jumpVelocity;
 
 jumpVelocity.x = rigidbody.velocity.x; // Preserve the x and z axis of the velocity
 jumpVelocity.z = rigidbody.velocity.z;
 jumpVelocity.y = 10.0f;  // The jump force
 
 rigidbody.velocity = jumpVelocity;

You can still use Rigidbody.AddForce, but usually not, and if you would, it would most likely have a ForceMode.Impulse modifier apart of it, like so:

 rigidbody.AddForce(new Vector3(0, 10, 0), ForceMode.Impulse);

Now, you want to have a hanging "cartoonish" effect when your character jumps. Using either of these options is plausible, but would require a large amount of fine tuning to get your character to do what you please.

The final thought is that what you can do is 0 out the y velocity for the rigid body for a set amount of time, but then "let go" of the rigid body by letting the y axis of the velocity be free. I wish I could give you an example, but I don't have the time right now.

Hope this helps.

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

Answer by GameTime45 · Apr 09, 2015 at 04:29 AM

Thanks for all the help guys. I actually thought of another way to handle it was well, when the vertical force decreases to a certain threshold but before it hits 0 I decrease the drag on the rigidbody so you are given more "airtime".

I'll give the alternatives everyone presented a look as well. Thanks!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

my jump key works about once every 10 presses 1 Answer

I really need a JumpPad script for a JumpPad in unity 2D 0 Answers

How do I fix this stupid jump animation not transitioning 1 Answer

JumpPad script for a JumpPad like Geometery dash 1 Answer

My player does not jump on every click and if it jumps it is really short 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