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 megabrobro · Dec 12, 2017 at 11:44 PM · physicsrigidbodyjumping

Changing the speed and accelleration of a jump using the built-in Physics Rigidbody engine in Unity?

Hi all, I have started making a basic platformer game just for fun. Its going to be the style of the original Super Mario Bros game, but with 3d assets.

My problem is that I'm using a rigidbody and using code I have always used to make my player object jump. It seems really slow. I am using a capsule object, the standard size (which is 2 units height). I have played about with the mass, ive tried 1 and 40. And other than having to increase the 'jumpForce' value accordingly, it seems to have not changed the jump speed at all.

So I'm hoping there is a way to tweak the flight of the jump whilst still using the Rigidbody component, and if so how please?

If not, I think I'm able to write my own code to make the gravity etc, but this seems stupid since Unity is a well established game framework I expect other people have also needed to change it and I'm sure there is a way I just don't know about.

Hope someone can help me.

Many thanks!

PS (Here is the basic code I have to make the character jump):

 public class PlayerController : MonoBehaviour {
     Rigidbody rb;
     Vector3 faceRight = new Vector3(0, 90, 0);
     Vector3 faceLeft = new Vector3(0, -90, 0);
     float halfHeight;
 
     float speed = Constants.speed;
     float jumpForce = Constants.jumpForce;
 
     private bool IsGrounded()
     {
         return Physics.Raycast(transform.position, Vector3.down, halfHeight + 0.1f);
     }
 
     void Start () {
         halfHeight = GetComponent<Collider>().bounds.extents.y;
         rb = GetComponent<Rigidbody>();
         rb.transform.Rotate(0, 90, 0); // make the capsule face right at start.
     }
     
     void Update () {
         HandleKeys();
     }
 
     void HandleKeys()
     {
         if (Input.GetKey(KeyCode.A))
         {
             if (rb.transform.eulerAngles != faceLeft)
                 rb.transform.eulerAngles = faceLeft;
 
             rb.transform.Translate(Vector3.forward * speed * Time.deltaTime);
         }
         if (Input.GetKey(KeyCode.D))
         {
             if (rb.transform.eulerAngles != faceRight)
                 rb.transform.eulerAngles = faceRight;
 
             rb.transform.Translate(Vector3.forward * speed * Time.deltaTime);
         }
         if (Input.GetKeyDown(KeyCode.Space) && IsGrounded())
         {
             rb.AddForce(Vector3.up * jumpForce, 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

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

140 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

Related Questions

Why wont my character jump? (using rigidbody and addForce) 1 Answer

Cannot move and jump with rigid body. 0 Answers

Rigid body floating the air when I jump at a wall... how do I fix? 2 Answers

Jump forward then back initial position 0 Answers

Preventing rigidbodys from jumping on a tiled map 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