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
1
Question by Hydropulse17 · Jun 15, 2017 at 06:52 PM · velocityaddforcemathjumpingrigidbody physics

Achieving consistent jump height regardless of vertical velocity

I keep my player object (Rounded cube, like dice) in steady horizontal motion by directly changing the velocity.

 cubeRB.velocity = new Vector3(maxVelocity, cubeRB.velocity.y, 0);

Vertical velocity is unconstrained, so as it moves along the ground, it bounces and spins without slowing down.

The user can press space to add a positive force to the y axis in order to jump. The problem is that since my cube is bouncing, its vertical velocity at the time of the jump is virtually always going to be negative or positive, which creates a great deal of inconsistency in jump height.

I imagine to remedy this, I'll need to do some kind of math with the current vertical velocity and how high I want the cube to jump, but I don't math very well... Any ideas or a solution would be greatly appreciated.

Jump code:

 cubeRB.AddForce(0, jumpForce, 0, ForceMode.Impulse);
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by elenzil · Jun 16, 2017 at 06:24 PM

if you want every jump to max out at the same height, what do you want want to happen when the player jumps while already in a jump up ?

if you really want every jump to max out at the same height, then it seems like you'd want to:

  1. if the cube is already going up, jumping should have no effect.

  2. if the cube is going down, jumping should set the vertical velocity to the negative of the current vertical velocity.

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 Hydropulse17 · Jun 16, 2017 at 07:19 PM 0
Share

The player can't jump again mid-jump, I've already coded for that. But it can jump while bouncing off the ground naturally.

Anyways, I wasn't getting an answer and couldn't figure it out, so I'm taking an alternative approach to the movement mechanics.

avatar image
0

Answer by Ewejose123 · Jul 10, 2017 at 08:54 AM

Hello, i just started unity less than a week but i think i know what do you mean and how to get it. In order to get a more consisten jump when you add a force, you need to change the Y velocity to 0 first, then apply the force and it will always be the same.

 cubeRb.velocity = new vector3 (cubeRB.velocity.x,0,0);
 
 cubeRB.AddForce(0, jumpForce, 0);

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 franconecat · Jul 28, 2020 at 12:48 PM 0
Share

This worked for me. Thanks!

I was adding a force to a rigidbody to make it jump. The idea was to implement a second jump while the body was in the air.

But it depended a lot on the vertical velocity of the body.

If the second force was added while the body had a positive or high vertical velocity the body jumped too much.

If the second force was added while the body was falling (with negative vertical velocity) the second jump was almost imperceptible.

This solution stops the body and makes it jump again as it were on the floor.

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

70 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 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

2D character can't jump off of platform floating in water 0 Answers

How can you instantiate a prefab with an initial burst of speed using ForceMode2D.Impulse? 2 Answers

Setting a delay before dashing. 1 Answer

How to calculate GameObject's velocity from AddForce. 0 Answers

Problem with making an object bounce. 2 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