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
1
Question by Fikule · Dec 14, 2014 at 08:54 AM · velocitygravityjumpjumpingunits

Jumping a specific height using Velocity & Gravity

Hello,

I am trying to get my character to jump a specific height using velocity and gravity.

Gravity is currently set to X:0,Y:-20

But, what is gravity? does the -20 mean it is applying a -20 unit velocity per second? This is all I can assume.

Anyway, to keep it simple, lets say I want to jump up 10.0 units. By this, I mean, from the character's position on the ground, to the peak of his jump, he should have moved 10.0 units.

However, I am pretty bad at the maths. So, gravity is -20 units, I need to peak a jump at 10 units. What velocity would I require?

rigidbody2D.velocity = new Vector2 (0, What goes Here?);

Of course, I am after the equation required, not just the number for 10 units. The character would need to jump 2 units, 5.5 units, 34.44 units, etc.

Comment
Add comment · Show 3
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 Fikule · Dec 23, 2014 at 08:21 AM 0
Share

Anyone? :)

avatar image WillNode · Dec 23, 2014 at 09:23 AM 0
Share

what mass you applied for your rigidbody2D?

avatar image Mmmpies · Dec 23, 2014 at 09:52 AM 0
Share

Always ways round not being good at maths. I take it you can get your character to jump so stack 10 cubes (or one and scale so it's 10 units in size).

Place that near your character and a camera to view side on your character. Disable any Camera setup you currently have whilst doing this and just view from the side on camera. Hmmm your 2D so you may already have a perfect camera for this.

Run the game and make your character jump. Then keep adding extra force until you get what you want. Should only take a few goes and you'll get a feel for how the velocity works as well.

EDIT: Oh your 2D so it might not be cubes, but just add something that's the height you want your character to jump so you can see it on screen.

1 Reply

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

Answer by Fonserbc · Dec 23, 2014 at 10:18 AM

From: http://en.wikipedia.org/wiki/Acceleration#Uniform_acceleration

Using the 3rd formula you can allienate v0 when v is equal to 0, when the object is on its maximum height.

 v0 = sqrt(-2 * a * s)

Which in unity would be something like:

 float jumpHeight = 10.0f;
 rigidbody2D.velocity = new Vector2(0, Mathf.Sqrt(-2.0f * Physics2D.gravity.y * jumpHeight));

This will make the object reach quite close to the jumpHeight, but you have to understand that the physics simulation is not deterministic and will not exactly make the object reach your height, but it will be pretty aproximate.

That is always that you have no drag.

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 Fikule · Dec 23, 2014 at 02:57 PM 0
Share

Thanks, this is what I was after. It isn't exact as you say, but it gives me a variable jump height that fairly accurately measures my touch position.

Cheers! :)

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

Anti-Gravity isn't working 1 Answer

Trying to limit air velocity 2 Answers

Gravity and jumping is wierd 1 Answer

Jumping script WONT WORK!!!!!!!! for 2D 1 Answer

Why when i press space button nothing was happened 0 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