- Home /
Unity3D editor not allowing large floats as input
Hey,
I'm trying to accurately represent the Earths mass and relate that to a persons mass to calculate gravitational forces between the two bodies.
I have no issue if the earths mass is set programatically, or calculated. However, I can't seem to input it into the editor. The editor keeps changing the value to something lower, or reverting to my previous set mass on the RigidBody. I'm attempting to set them in the editor so I can place certain planets with specified weights.
Is there a restriction on the float values in the editor thats lesser than that which can be represented in C# scripts in Unity? Or am I going about this in the wrong way?
Cheers.
Where are these floats? Are these $$anonymous$$ass values for rigidbodies? The tooltip on the mass clearly indicates that those values are clamped at 1e-07 and 1e+09 (likely for efficiency). Internally, floating point numbers cannot exceed 9.999946e-41 and 1e+38 without generating a number overflow. I suspect Unity's physics is also internally clamping your programmatically set values when it uses them, making your coded value changes meaningless beyond the clamped values anyways. If it isn't using the your code-set values and you really need them that precise, you will need to calculate your own physics.
Answer by starkos · Mar 08, 2011 at 02:39 PM
Perhaps you could compute the force of gravity in a script, using double-precision numbers (use "double" instead of "float"). Then set the computed gravity on the physics manager, or on the specific rigid bodies as needed. If you only need to do this once (like, when you land a new planet) that should suffice. If you need to do it constantly (like, for a spaceship flying near a planet) you could calculate it in Update(), or maybe in a coroutine that fires every few seconds if it isn't changing drastically.