Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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
6
Question by bob97470 · Oct 26, 2011 at 10:45 PM · physicscollideraddforceinconsistent

addforce seems inconsistant

new user here. I've been working on the game mechanics for a simple 2d platformer, not unlike super mario. Anyway, I've been using addforce as a way to launch my char(a simple rigidbody cube) into the air when the jump button is pressed.

The problem: if the char is standing on a single platform(collider), then addforce propells the char a certain number of units into the air(as expected), however, if the char is resting on multiple platforms(half on this, half on that) then the same addforce code has a diminished effect(char is propelled considerably less)

The question: is this normal behavior or some overlooked problem with the physics engine? Is there a workaround? Has anyone else noticed this behavior?

The behavior is simple to reproduce. Simply create 2 cubes and scale them long in the x axis. Now place them next to each other on the x axis at equal height. Now we have 2 platforms adjacent to each other. Place a third cube(char cube) ontop of the platforms and add a rigidbody for physics. Now apply an addforce in the vector3.up direction using a power of 300 and note the altitude of the jump. Try this experiment while touching both platforms and while touching only one. When I do this, there is a significant difference in the altitude of the jump.

Any thoughts?

Comment
Add comment · Show 1
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 LegionIsTaken · Oct 28, 2011 at 05:47 PM 0
Share

This should be an example to all new members. This guy is new and yet he asks a near perfect question ins$$anonymous$$d of just "y no wrok?", while having a original question +1 for that my man. Good luck.

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by SpaceManDan · Sep 24, 2019 at 12:45 AM

I was having this problem. I was processing all related button presses and calculations in FixedUpdate. Simply moving all the input collection and value processes into Update and triggering the force application from FixedUpdate fixed the problem. It was very simple just to have a Boolean activate once ready to apply forces.

Example:

UPDATE

Get button press

Calculate values

Set boolean (applyForce) to true.

FIXEDUPDATE

If boolean (applyForce == true) rb.addforce

Set boolean (applyForce) to false.

Pretty simple. Just put the actual physics stuff in FixedUpdate and calculate everything else in Update and apply Time.deltaTime to the things applying physics over several frames (i.e. not impulse but force).

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
1

Answer by aldonaletto · Oct 26, 2011 at 11:04 PM

I don't know exactly what is causing this, but I suspect you will have best results setting the rigidbody.velocity instead - something like this:

 if (Input.GetButtonDown("Jump")){
     rigidbody.velocity.y = jumpSpeed;
 }

The results are way more predictable - AddForce is affected by the rigidbody mass, the previous velocity and the time during which the force is applied.
Also do the jump in Update, not in FixedUpdate - Input.GetButtonDown may return true in two or more FixedUpdates if the frame rate is below 50 fps (the default physics rate), with could double or even triple the jumping 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
avatar image
1

Answer by bob97470 · Oct 28, 2011 at 04:07 PM

I'll give setting the velocity a try, thx.

Yeah, I've already discovered that grabbing inputs inside fixedupdate is a bad idea. Thoug theh docs say addforce should be applied there. I got around that by grabbing my input in update, and applying the force in fixedupdate, while at the same time only allowing a single jump until the last one has been executed. This gives me reliable results, except while standing on two platforms. (Which I still don't understand.)

Comment
Add comment · Show 2 · 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 rustofelees · Jan 03, 2015 at 02:20 AM 0
Share

Also new to Unity and am experiencing the same problem. Did you every discover what was happening?

avatar image VishwasGagrani · Jan 24, 2021 at 06:37 PM 0
Share

That's happening with me too. $$anonymous$$oved all the inputs to update(). Previously they were inside fixedUpdate and were making AddForce unpredictable and inconsistent. $$anonymous$$oving inputs like GetAxis to update solved the issue.

avatar image
0

Answer by Araj-Tejani · Oct 05, 2016 at 09:53 AM

All code write in FixedUpdate and AddForce forceMode.Force the result will be accurate

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

8 People are following this question.

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

Related Questions

Copy object Movement/Addforce on Trigger to other object,Copy object Movement/Force to object in Trigger 0 Answers

How to make add force/Physics consistent between editor and builds? 1 Answer

Attempting to make rigidbodies clump together, as if in a ball. 0 Answers

Accelerate a rigidbody towards max speed 2 Answers

Make Ray hit own collider 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