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.
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.
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.
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.
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
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
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;
}
}
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?