objects with a mass greater than the limitations of the standard rigidbody component

I was wondering what would be the best way to to handle an object with a greater mass than the limitations of 1m of a standard rigidbody. For example a planet.
Lets say the planet in question is the earth, which has the mass of 5.972e+24 which as I undersand is how unity sees it, which written as a standard number is 5973600000000000000000000 (yup thats alot of zeros)
A standard rigidbody’s limitation is 1e+09 which is 1000000000 (alot smaller)

The reason I am asking this is because I want to realisticly simulate a solar system and the gravitational effects of the orbiting bodies within it. This would also include objects like man made satelites with a much smaller mass for example the ISS is 450,000 and a human is an average of 70.8 give or take a few kg.

Some solutions I could think of were these.

  1. Scale down by many zeros and recalulate the gravitational forces based on the scaling which brings the planets within a handleable range.
    Cons - This then moves smaller objects like satelites and human sized objects outside of the range of rigidbodies which have a decimal limit of 0.0000001.

  2. Handle the gravitational physics manually through code and handle the object physics on a local scale through physX largely eliminating the issue.
    Cons - This causes alot more problems like colision problems with smaller objects and planets amongst others.

I have the gravitational forces down to a tee on smaller objects below the ridgidbody limitations but scalability is an issue and I’m pretty sure floating point errors will come into play but that’s another bridge.

Has anybody any ideas, workarounds or solutions for me?
Any help would be apreciated and thanks in advance.

bump*

Bump :wink:
does nobody care about the laws of physics?

Probably because it cant be done, at least with the current PhysX implementation. If you use numbers that are too small you will be prone to floating points errors like you mention and that will affect the very small objects in a very undesirable way. And then PhysX recommends to make masses of rigidbody not more or less than 100 times that of other Rigidbodies. Otherwise you can get really weird behaviours.

This info is clearly a limitation which is stated in the docs and can be found here :http://docs.unity3d.com/Documentation/Components/class-Rigidbody.html

So I don’t think you can get the same scale and mass as in real life and not even the keep the same ratio if you’d bring every number down. The way I see it, there would always be problems somewhere. But you’re welcome to prove me wrong :P.

To my knowledge, PhysX will not calculate inter-object gravity, anyway, no matter what the mass. “Gravity” as far as Unity knows is just an acceleration constant applied to all rigidbodies in a particular worldspace direction.

PhysX is not a physics simulator; it is a physics special effects simulator, really. Good for blowing up boxes and walls and such. You need to get outside the PhysX box and probably write your own system to do this kind of thing.

6 years later…
Have you figured it out yet? I’m doing a solar system model just as you and I’m having the same problem. My solution is to create my own “RigidBody” behaviour, and apply all physical behaviours myself. The problem is that I can’t deactivate PhysiX so it will still eat some of the performance :frowning:

There’s actually another way to look at it. If you think about it, while the gravitational pull between planets is very hight, the actual acceleration they’ll suffer from it is within the range of a float. So you can make the calculations yourself using doubles and apply the resulting acceleration to the rigidbody. You probably already have a script calculating the gravity using newtonian mechanics anyway, so just have a property in them hold the mass of the body in a double type property. Too bad it is now 9 years later hahaha

You’re not going to get a good result for orbital mechanics with Unity’s builtin physics engine.

Here’s a video describing a better approach:

1 Like

I’d recommend implementing your own physics like system for implementing gravity and movement with double precision.

A couple months back I wrote such a system to prototype the behavior of stars and supermassive black holes. Was actually a lot of fun. I think the prototype only took about 10 hours or so of my time. Not sure, because I spent as much time watching the simulation as writing it.

I am extremely late to the party but i have found a workaround. i created a mass override script that inputs a custom mass into the rigidbody and it works!

public class MassOverride : MonoBehaviour
{
    public float mass;
    private Rigidbody2D rb;

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        rb.mass = mass;
    }
}
1 Like

wOuld changing everything to earth masses, radius’, density. etc work?

Please don’t necro-post, espeically with vague questions about “would it work.”

If you have a new question, make a new post. It’s FREE!!

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379

  • Do not TALK about code without posting it.
  • Do NOT post unformatted code.
  • Do NOT retype code. Use copy/paste properly using code tags.
  • Do NOT post screenshots of code.
  • Do NOT post photographs of code.
  • ONLY post the relevant code, and then refer to it in your discussion.

I didn’t know about that but it makes sense.

Good to know!