How to handle a infinite 2.3333333 number?
Hello everyone
I'm on a project to make a kind of simulations of planetary gears
as I can not make them react to each other with the colliders
I try to do it with a Script that calculates the speed of each part as a function of the input speed and the role that each party shall perform
in this case, the sun is the entrance, the carrier is stationary, and the ring is the output
the calculation for ring ratio would look like
-S/R = -52/92 = -0,5652173913043478
and for planets ratio would look like
-S/P = -52/20 = -2,628260869565217
Now, I have the speed of the input into an int, so to be, for example 45 the velocyty for each part would look like
VR= 45*-0,5652173913043478 = -25,43478260869565
Vp= 45*-2,628260869565217 = -118,2717391304348
but for some reason Unity does not use numbers with decimals all full, and thus, do not get the proper spin on each gear
this had me upset the script works so fine but, the end is not that all,
any idea how to fix this?
instead of doing it this way
Will there be another?
for example, it occurs to me that not as a function of its speed but in terms of its angle of rotation, but not really seriously need to fix this.
I appreciate all the help you can give me
Answer by Dibbie · Jun 21, 2016 at 05:50 PM
Im assuming your using a comma (,) instead of a period (.) as its easier to see in your calculation? But in Unity, you should certainly be using a period/decimal (.) whatever youd like to call it.
Float conversions have to be continuous, so even for example, your 45, should be 45f or (float)45 so that math takes every number as a "float" when converting.
If it isnt calculating all numbers, try using a long, or a double, another thing you could try is BEDMAS to handle larger numbers into a temp variable, then calculate the result of both of those into a even longer variable. Your numbers dont seem like they would be too large for a float to handle though. I cant remember how many digits a float is capable of managing off the top of my head, but im confident its more than what you have there.