• 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
Question by IanGRap · Oct 11, 2016 at 05:23 AM · movementrigidbody2daddforcejumping

Rigidbody2D AddForce only working with large numbers

I have a character that I am trying to make jump. I can make them move left and right with inputs and setting velocity and what not, but the jump isn't working. I'm using AddForce like so:

alt text

"Jump" appears in the console so the function is being called, but the character doesn't move. However, when I put the number being multiplied in the function (125) to something really high like 500, the character shoots up in the air. Does anyone know why it is working like this?

screen-shot-2016-10-10-at-82636-pm.png (73.8 kB)
Comment
KokodokoGames

People who like this

1 Show 2
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 Sergio7888 · Oct 13, 2016 at 06:24 AM 0
Share

AddForce is based on the Rigidbody mass, heavier thing need more force, if you specify ForceMode in the second parameter of the AddForce, some ForceMode ignore mass value.

avatar image iamsidv Sergio7888 · Oct 13, 2016 at 06:57 AM 0
Share

Yes, this indeed is the solution that @sergio7888 pointed out because by default AddForce adds force on the rigidbody's mass. In your case, I'd recommend you to use ForceMode.Impulse or ForceMode.Velocity in the second parameter of the AddForce method, depending on your use.

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by IanGRap · Oct 13, 2016 at 07:00 AM

Figured it out. I had the gravity scale set super high on the associated rigid body 2d.

Comment
Orokon
Sergio7888

People who like this

0 Show 0 · 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

Answer by Naphier · Oct 13, 2016 at 06:59 AM

A few things here:

  1. You're applying force every fixed update frame. This means you are apply this force around 60x per second. This means by the time the character leaves the ground a lot of force has been added.

  2. Think of reality. If you jump do you continually have a force pushing you upward? No. It's more of an instantaneous force. For this reason we most commonly use ForceMode.Impulse which applies the amount of force indicated times 1 second. So the total force that would be applied over 1 second of time is applied instantaneously. Force = mass * distance / time^2.

  3. Don't do this with Input.GetButton, instead use Input.GetButtonDown to only register a single keypress until the key is released and pressed again.

  4. Make sure you have your drag set up properly (usually little drag is appropriate) and make sure your mass is sufficient (usually 1 is OK). Other than that double check your gravity is set to -9.81 m/s^2.

  5. Last one, don't ever put Debug.Log statements in an Update loop, they block the main thread and slow your application. Learn how to debug things like this with OnGUI or exposing variables in the inspector.

Comment

People who like this

0 Show 0 · 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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rigidbody2D.AddForce is not moving the object 0 Answers

How to limit rotation angle on a rigidbody2d ? 0 Answers

[C#, 2D] How do I apply force to a player using vector 3 velocity to move 1 Answer

Unity 2D addforce problem 1 Answer

Rigidybody2D addforce at constant speed 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