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 ej469 · Feb 02, 2015 at 11:07 AM · rigidbodyvelocityjumpingforce

How to get the same jump height each time

I've been trying to make a 2.5D game in Unity and I need the characters to jump similar to characters in BlazBlue. I've been trying to make it so that no matter the direction of the jump that the jump always reaches the same height:

http://gyazo.com/5974028acf46a1941ec7abca2d12938b http://gyazo.com/7de2ea2cf6a9d64650ac49a242dec9b1 http://gyazo.com/af951e967d3bfce231166f7c273b0cab

I've been using rigidbodies that have everything except their x and y positions frozen and have apply gravity checked whenever I change the y velocity of the rigidbody. The problem is that changing the jump force makes the jump heights really inconsistent and sometimes doesn't really make much change at all:

 void Jump() {
     if (Input.GetKeyDown(moveRight)) {
         Vector3 vel = rigidbody.velocity;
         vel.y = jumpHeight * jumpHeight;
         rigidbody.velocity = vel;
         isFalling = true; 
         airAction--;
     }
     if (Input.GetKeyDown(moveLeft)) {
         Vector3 vel = rigidbody.velocity;
         vel.y = jumpHeight * jumpHeight;
         rigidbody.velocity = vel;
         isFalling = true; 
         airAction--;
     } else {
         Vector3 vel = rigidbody.velocity;
         vel.y = jumpHeight;
         rigidbody.velocity = vel;
         //rigidbody.AddRelativeForce (transform.up * jumpHeight, ForceMode.Force);
         isFalling = true; 
         airAction--;
     }
 }

I've tried applying force already and using CharacterControllers seems to only make it worse. Is there any way I can acheive this effect?

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 AlwaysSunny · Feb 02, 2015 at 02:25 PM 0
Share

Not for nothing, but using real rigidbody physics and expecting to get the exact same results in different scenarios isn't feasible. Not without some major foresight, case-planning, and prototyping. There are a ton of tricks and quirks involved in making a great rigidbody controller; frankly too much to expect to be taught. You've gotta learn them as you go.

You can either jump by adding a one-time impulse force (or velocity change) whose magnitude is the same each time, which is the conventional, widely-appreciated method. Or you can create your own system to govern jump force based on whatever methodology you want.

edit: having just checked out your example screenshot, I'm not convinced you should be using non-kinematic rigidbodies at all.

2 Replies

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

Answer by Jaidan · Feb 02, 2015 at 04:02 PM

Hello, i think i might have the answer, i asked this same question a couple of days ago and got a brilliant reply from a guy, here is the answer page: http://answers.unity3d.com/questions/890058/fixed-height-jumping-2d-c.html

If you have any questions then ask the guy who answered the question. :D

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 ej469 · Feb 04, 2015 at 11:03 PM 0
Share

It didn't work perfectly, but with a few adjustments I was able to get it really close. :) Thanks!

avatar image
0

Answer by Nemox · Feb 02, 2015 at 05:32 PM

For one, you're setting vel.y to different things. When moving it's jumpHeight^2, but when not moving it's just jumpHeight.

Also double-check that the function isn't accidentally getting called multiple times. It could accidentally be checking that ground is under the character's feet, even though the character is moving away from it.

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

Rigidbody velocity has got different direction than VelocityChange force vector 1 Answer

How can you apply force or set the velocity of a rigidbidy on local axis? 1 Answer

Rigidbody Character 1 Answer

relativeVelocity how to? (noob question) 2 Answers

AddForce doesn't work when used with velocity 3 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