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 PixelProtist · Apr 17, 2014 at 12:57 AM · timejumpplatformer

Changing jump speed so that different height jumps take exactly the same amount of time?

This is my first question, so I don't know how soon to expect a reply, but I heard that a survey a while back showed that the controls in games featuring jumping were found the most pleasurable in games where, each time the player jumped, he spent the same amount of time in the air each jump. Even though the height could be dependent on the length of time the button was held, the exact time before the player landed again was the same each time.

I was wondering if there was a logical way of making this in JavaScript, so you can calculate the different height jumps' speed to fit a time. Anyone who knows/can work out how to do this, I would very much appreciate if somebody could give me a hand with this, as I have no idea how to go about altering speeds to suit an amount of time.

I am currently using a cube with a character controller attached to run my script, which currently features no height alteration in the jump, as I wanted to do it with a fixed time involved. :) Thanks in advance :D

 var jumpSpeed = 9.0f;
 var gravity = 14.0f;
 var maxFallSpeed = -4.0f;
 var canJump : boolean = true;
 private var controller : CharacterController;
 private var moveDirection = Vector3.zero;
 
 function Update()
 {
     controller = gameObject.GetComponent(CharacterController);
     
     if (controller.isGrounded)
     {
         if (Input.GetButton("Jump"))
         {
             if (canJump == true)
             {
                 moveDirection.y = jumpSpeed;
                 canJump = false;
             }
         }
     }
     else
     {
         if (moveDirection.y > maxFallSpeed)
              {
                 moveDirection.y -= gravity * Time.deltaTime;
             }
     }
     
     if (Input.GetButtonUp("Jump"))
     {
         canJump = true;
     }
     
     controller.Move(moveDirection * Time.deltaTime);
 }
Comment
Add comment · Show 4
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 robertbu · Apr 17, 2014 at 03:21 AM 0
Share

In order to answer this question you need to spell out 1) how you are moving things in your app (CharacterController, Transform, or Rigidbody), what your current jump code looks like for that type of movement, and how the user would cause the object to jump to different heights.

avatar image PixelProtist · Apr 19, 2014 at 08:54 AM 0
Share

Thanks, I have made the changes :)

avatar image koray1396 · Apr 19, 2014 at 09:48 AM 0
Share

well, just my opinion, but this is quite difficult, as you can not know how long the player will press the button in advance. but you can increase velocity as long as the button is pressed, decrease it to zero until jumpTime / 2, decrease speed by average on fall. And you can define until when the speed will increase, such as jumpTime / 4...

 if(jumping){
     counter += Time.deltaTime;
     if(Input.GetButton("Jump") && counter < jumpTime / 4f){
         rigidbody.velocity += new Vector3(0f, jumpAcceleration * Time.deltaTime, 0f);
         velocity$$anonymous$$ax = rigidbody.velocity;
     } else if (counter < jumpTime / 2f){
         rigidbody.velocity -= new Vector3(0f,((jumpTime / 2f) - counter) * velocity$$anonymous$$ax * Time.deltaTime, 0f);
         jumpHeight = transform.position.y - beforeJump.y;
     } else if (counter >= jumpTime / 2f){
         rigidbody.velocity -= new Vector3(0f, 2f * jumpHeight / $$anonymous$$athf.Pow(jumpTime / 2f), 2)* Time.deltaTime, 0f);
     }
 }

Please note the above will not work properly and have problems, needs quite modification, the player will jump again if you press jump twice for example, and actual jumpTime will be a little different from what you define, due to delta time. But i think it might give you a general idea.

Of course someone smarter than me will come up with something better, that's how i would do.

Also below link is a useful one for proper calculation of velocity.

http://www.niksula.hut.fi/~hkankaan/Homepages/gravity.html

avatar image PixelProtist · Apr 19, 2014 at 01:14 PM 0
Share

Thanks a lot, koray1396 :D I shall have a go at making that script work and post a solution here if/when I can make it work. :)

0 Replies

· Add your reply
  • Sort: 

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

21 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

Related Questions

Dynamic jump? 1 Answer

2,5D game jump script with multiple linecasts to check if grounded 1 Answer

I'm making a 2D mobile platformer and I just figured out how to make the mobile buttons work. But I can't get the jump limit to work. Does anyone know how to create maybe a ground detection with this script? 1 Answer

Jump implementation in multi level platforms game 1 Answer

How to do 2 distinctives jumps relative to the time the key spent down? 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