Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
1
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
Add comment · 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 Force$$anonymous$$ode in the second parameter of the AddForce, some Force$$anonymous$$ode 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 Force$$anonymous$$ode.Impulse or Force$$anonymous$$ode.Velocity in the second parameter of the AddForce method, depending on your use.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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

6 People are following this question.

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

Related Questions

Simple Rigidbody2D movement and jump 0 Answers

2D "Platformer" Movement Problems 1 Answer

AddForce from Two Sources 1 Answer

Rigidbody.Addforce makes object skip 5 Answers

How do i make jumps follow through with rigidbody2D.addforce? 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