Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 EmmetOT · Jan 27, 2021 at 11:55 PM · physicsmathplatformermotion

Calculate jump velocity given horizontal distance and speed

I'm making a 3D platformer with a fairly consistently physics-based controller. Up until this point, my designer has been satisfied specifying jump height in meters. I can then calculate the vertical speed required to reach this height with the following method:

 private float GetJumpSpeedGivenHeight(float height) => Mathf.Sqrt(-2f * Vector3.Dot(Physics.gravity, UpAxis) * height);

However, we want to be able to describe a jump arc given a horizontal distance to travel, and a speed to travel that distance, without caring about the height. Basically a function which takes two floats and gives a Vector3. (We can assume the jump is axis-aligned for simplicity's sake)

I understand that this would involve use of kinematic equations, but I'm at a loss as to how to continue. If someone could give me a nudge in the right direction that would be amazing.

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
1

Answer by Eno-Khaon · Jan 28, 2021 at 03:39 AM

Based on an old answer I gave here, there are multiple approaches you can take to this problem.

Since you're describing "a speed to travel a certain distance without caring about height", you can use a time-based approach (HitTargetAtTime() in my example), where the time is directly tied to horizontal distance traveled.

For example, by having a predetermined horizontal speed, the launch velocity would be calculated using something like:

 public float horizontalSpeed = 50.0f; // Units per second, must be [> 0]
 // ...
 Vector3 flatFromTo = targetPosition - transform.position;
 flatFromTo.y = 0f; // Simple example of eliminating height, assuming y-axis-only gravity
 float flatMagnitude = flatFromTo.magnitude;

 // timeToArrival = horizontalDistance / horizontalSpeed
 Vector3 launch = HitTargetAtTime(transform.position, targetPosition, Physics.gravity, flatMagnitude / horizontalSpeed);


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
avatar image
0

Answer by EmmetOT · Jan 28, 2021 at 09:58 PM

In the end the answer was painfully simple. These give the upward speed required to make the jump.

 public static float GetJumpSpeedGivenHeight(float height) => Mathf.Sqrt(-2f * Vector3.Dot(Physics.gravity, UpAxis) * height);
 public static float GetJumpSpeedGivenTime(float time) => -Vector3.Dot(Physics.gravity, UpAxis) * 0.5f * time;
 public static float GetJumpSpeedGivenSpeedAndDistance(float speed, float distance) => GetJumpSpeedGivenTime(distance / speed);

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

191 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 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 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 360 degress platformer example needed 0 Answers

My character moves in seemingly random directions. 1 Answer

2D Character Movement Collision Problem 0 Answers

Force in Circular Motion 1 Answer

Convert from m/s to m/fixedFrame 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