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 RealMTG · Aug 25, 2016 at 09:23 AM · jumpcharacter controllerfixed

Fixed character controller jump height

Hello

I am currently working on a player controller using Unity's built-in character controller and I would like the jump height to be fixed. Right now I am simply doing "moveDirection.y = jumpHeight;" and it works but it is not really what I want. The jump height is set to 10 and that results in the player jumping ~2 meters up in the air. But how do I make it so, for example, I set it to 3, the player jumps meters into the air?

Any help is appreciated!

Comment
Add comment · Show 9
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 RealMTG · Aug 26, 2016 at 02:36 PM 0
Share

Any help with this?

avatar image Dream_in_code · Aug 26, 2016 at 02:41 PM 0
Share

If you set to 3 then how much meter you want to jump?

avatar image RealMTG Dream_in_code · Aug 26, 2016 at 02:43 PM 0
Share

If I set it to 3, I want to jump 3 meters. If I set it to 5.2, I want to jump 5.2 meters. Currently, if I set it to 3, I only jump ~0.4 meters.

avatar image Dream_in_code RealMTG · Aug 26, 2016 at 02:49 PM 0
Share

in that case you can multiply the jumpheight by the input jump value(jumpheight * input value)

Show more comments
Show more comments
avatar image RealMTG Dream_in_code · Aug 26, 2016 at 02:54 PM 0
Share

Sorry about replying to the wrong comment but it's the only way for me to actually reply. >_>

But how do I know what I should multiply it by?

avatar image Dream_in_code · Aug 26, 2016 at 03:57 PM 0
Share

Looks like you need to play with gravity scale a bit. You wrote that the player will jump 2m if the jumpheight is 10 but what is the gravity scale? change the gravity scale so that when you press 10 it will jump 10meter. After you find exact gravity scale multiply it with jumpheight. Example you reached 10m in 1 gravity scale then to reach 20 you do 20* 1;

avatar image RealMTG Dream_in_code · Aug 26, 2016 at 04:47 PM 0
Share

Ah, I see. I will experiment around with this and see if I can find a working solution! Thanks for the help so far!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DavidWatts · Aug 26, 2016 at 06:13 PM

i believe the calculation you want is

Mathf.sqrt( 2 * jumpHeight * -Physics.gravity.y );

Comment
Add comment · Show 11 · 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 RealMTG · Aug 26, 2016 at 06:51 PM 0
Share

I'm a bit confused about that 2. $$anonymous$$ind explaining?

avatar image stanogg RealMTG · Aug 26, 2016 at 06:56 PM 0
Share

he means: $$anonymous$$athf.sqrt(2 * jumpHeight - Physics.gravity.y); i guess

avatar image RealMTG stanogg · Aug 26, 2016 at 07:01 PM 0
Share

I figured so, eventually. But I can't actually get it to work with this equation. I do get some value but it is so small the player just lifts like 0.05 meters above the ground.

avatar image DavidWatts · Aug 26, 2016 at 11:52 PM 0
Share

sorry i was having issues with answers not working on firefox so i had to get chrome. yea i meant $$anonymous$$athf.sqrt( 2 jumpHeight - Physics.gravity ) and set it to the velocity.y not AddForce

avatar image DavidWatts · Aug 26, 2016 at 11:59 PM 0
Share

why cant i put in a star for multiplication?

avatar image DavidWatts · Aug 26, 2016 at 11:59 PM 0
Share

all 3 terms are multiplied

avatar image RealMTG DavidWatts · Aug 27, 2016 at 11:19 AM 0
Share

I tried doing this and it kinda worked, I guess. $$anonymous$$y problem is that I use a custom gravity parameter and if I change it, the jumping will be off. I also needed to change the 2 to 10 for it to work in the first place.

avatar image DavidWatts RealMTG · Aug 27, 2016 at 12:03 PM 0
Share

that should work with custom gravity just to be clear it is

 $$anonymous$$athf.sqrt( 2 * jumpHeight * -gravity.y )
Show more comments

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

55 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

Related Questions

I can't do that my character jumps while running 0 Answers

Best way to implement jump method for character controller 1 Answer

how can I make a character fly when holding down the jump button? 1 Answer

Fixed jump height 0 Answers

Extend simple movement script (C#) 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