• 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 MattTheProgrammer · Nov 05, 2013 at 04:18 AM · physicsgravityjumpspeed

The faster my character goes the longer he jumps.

Hi I'm making a endless runner/Temple run type game. My only problem so far is that the faster he's going, The longer he jumps(The character speeds up as he gets farther). What can I do about this? Im using rigidbody for Jumping.

Comment
Add comment · Show 8
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 hdgam3r · Nov 05, 2013 at 04:21 AM 0
Share

Are you using the AddForce method? If so, what parameters are you sending to it?

avatar image Huacanacha · Nov 05, 2013 at 04:29 AM 1
Share

This is expected behavior from a Physics or $$anonymous$$athematical perspective of course. You have a few options I can see to work around this, each with consequences:

  1. Calculate how much force to apply to always land X meters from the start of a jump - jumps will be lower the faster the player runs

  2. Increase (or supplement) the Gravity force the faster he runs - player will go up and down faster which may look a little odd at really high speeds

  3. Always set the speed to a constant value whilst in the air - player slows down whilst airborne

This is as much a design decision as anything... you may even decide to stick with the current situation after evaluating the options.

avatar image MattTheProgrammer · Nov 05, 2013 at 08:11 AM 0
Share

Could you give me an example please @Huacanacha

avatar image Professor Snake · Nov 05, 2013 at 09:04 AM 0
Share

It would be great if you could include some of your code with the question, so we can see exactly what needs to be done.

avatar image ozturkcompany · Nov 05, 2013 at 10:19 AM 0
Share

Just get the velocity of your player by rigidbody.velocity.magnitude and calculate your desired speed at a point and make a if statement. If velocity is greater than your desired speed add a drag to your player or add a counter force. Hope this helps

avatar image MattTheProgrammer · Nov 05, 2013 at 08:36 PM 0
Share

Sorry Heres my code:

 public class Runner : $$anonymous$$onoBehaviour 
 {
     public static float distanceTraveled;
     
     public float acceleration;
     
     private bool touchingPlatform;
     
     public Vector3 jumpVelocity;
     
     public Vector3 Gravity;
     
     public float gameOverY;
 
     void Update () 
     {
         if(touchingPlatform && Input.GetButtonDown("Jump"))
         {
             rigidbody.AddForce(jumpVelocity, Force$$anonymous$$ode.VelocityChange);
             rigidbody.AddForce(Gravity, Force$$anonymous$$ode.VelocityChange);
             touchingPlatform = false;
         }
         
         distanceTraveled = transform.localPosition.x;
         
         if(transform.localPosition.y < gameOverY)
         {
             Application.LoadLevel("GameOver");
             
         }
     }
     
     void FixedUpdate()
     {
         if(touchingPlatform)
         {
             rigidbody.AddForce(acceleration, 0f, 0f, Force$$anonymous$$ode.Acceleration);
         }
     }
     
     void OnCollisionEnter()
     {
         touchingPlatform = true;
     }
     
     void OnCollisionExit()
     {
         touchingPlatform = false;
     }
     
 }
avatar image meat5000 ♦ · Nov 05, 2013 at 08:40 PM 0
Share

Firstly, have you tried other forcemodes for jumpvelocity and gravity?

Also, you have AddForce calls in Update(). This is probably not a good idea.

avatar image nt314p · Sep 13, 2017 at 11:45 PM 0
Share

I think that you should have your character move at a set speed so that each jump will make him move the same distance.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Litleck · Sep 14, 2017 at 01:49 AM

Can I see your script for this, I cant get much information from this.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

22 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

Related Questions

The faster it goes, the longer it jumps 1 Answer

Constant speed when free-falling... Why?? 1 Answer

How to make a object jump constantly at y and move to the next position to z (perfectly) 0 Answers

gravity doesnt seem to effect my first person controller....help! 1 Answer

Edit this script so that on the second jump change the gravity to 5 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