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 DeaD4MaN · Apr 29, 2016 at 08:33 AM · physicsrigidbodyrigidbody2dphysics2drigidbodies

Inconsistent gravity/random forces/solver problem? (forum crosspost)

Maybe I'm not considering some fundamental forces, or even making stupid errors and assumption in the simplest of equations, or this is indeed an floating point precession error/physics solver error. But here are the steps to reproduce the problem (using Unity 5.3.4f1):

  1. Make a default 2D project with not additional packages.

  2. Make a scene with a BoxCollider2D for a floor and two identical objects with BoxCollider2D and RigidBody2D. Leave the first rigidbody as is, and set gravity scale to 0 on the second rigidbody.

  3. Add this script from this post on any object: http://forum.unity3d.com/threads/inconsistent-gravity-random-forces-solver-problem.400978/ (code tag is messing up)

  4. Populate the rb1 and rb2 fields with the two created rigidbodies.

  5. Play the scene and test the results by setting 'test' to true when BOTH of the objects are lying STILL on the ground. Do it a few times. Look how both of the objects get higher every time you set 'test' to true. In ideal physics they should reach the same height every time, or at least be within some boundaries, not higher EVERY time. This is minor gripe, I can live with it, since the difference is so small.

  6. Now set the 'scale' value to 0.5, for example, and do the same test as above. Correct me if I'm wrong, but since the applied force and the gravity is scaled by 0.5 for the second rigidbody it should have exactly half the acceleration, hence half traveled speed, because the force was and impulse. But if you compare maximum heights reached (scaling the second one up by the factor given) they don't add up. Even worse - the smaller the scale, the bigger the gap.

What am I missing here?

Comment
Add comment · Show 4
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 tanoshimi · Apr 29, 2016 at 08:58 AM 0
Share

I don't quite understand the test conditions, but gravity is applied to rigidbodies by the PhysX engine automatically (assu$$anonymous$$g that the "Use Gravity" checkbox is ticked, which it is by default), so by also trying to account for gravity manually in your code (with an additional scale factor), you're creating a strange situation. And the reason why they're getting higher every time is because you're never resetting the initial conditions.

What is the actual problem you're trying to solve?

avatar image DeaD4MaN tanoshimi · Apr 29, 2016 at 09:27 AM 0
Share

RigidBody2D does not have a UseGravity property, but has a GravityScale property, so by setting it to 0, it should effectively behave the same as setting UseGravity to false. So in this case I'm manually applying gravity, that the engine does by default.

The problem is the huge difference between simulations.

avatar image Eno-Khaon DeaD4MaN · Apr 29, 2016 at 09:46 AM 0
Share

One problem I see with the experiment, regardless of its outcome, is that Rigidbody2D.AddForce() does not appear to be an adequate testing measure for reproducing the gravitational force applied to an object.

The reason for this is that Force$$anonymous$$ode2D does not include options to ignore mass, which gravity most definitely (effectively) does. The problem would be extremely obvious with extremely high-mass objects.

In order to create a proper simulation, your gravitational influence should look more like:

 rb2.velocity += trueForce * scale;

and

 rb2.velocity += Physics2D.gravity * scale * Time.fixedDeltaTime;

As far as any resulting imprecision beyond that, I can't say for sure. But first, let's ensure that unexpected physical forces aren't involving themselves in the test.

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

increasing knockback of a rigidbody as received damage increases (like super smash) 1 Answer

How to make physics relative to moving parent 1 Answer

Rigidbody2D: Follow other Rigidbody2D strictly 1 Answer

Recalculating collisions after Physics2D.IgnoreLayerCollision()? 1 Answer

Child GameObject can't use MovePosition on parent's Rigidbody2D? 3 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