- Home /
Using more precise floats for movements.
How can I for example move my character and the result to always be like 2.315 and not 2.31460004 .
Any final position should be having no more than 3 followup numbers after the initial one.There should be consistent positioning occurring for each move. Determinism is key.
I need this, because using the raw float, results in inconsistent positions acrosss the network and client, in a authoritative mp model.
Positions and rotations in Unity are, and will always be, represented as vectors of floating-point values. But this in common with almost all common game frameworks. Can you explain in more detail why this presents a problem?
Answer by TomTheG · Jul 19, 2015 at 07:43 AM
One idea is to round off your floats to the decimal point you need before using them in the movement. I have used this in the past and it worked well.
You should be able to use: Math.Round("float to round", "decimal point to round to");
i.e. Math.Round(movementDistance, 3);
Even rounding will probably give a longer value, that's just how float works.
But is there anything to be done though ? I seem to be held back by the imprecision of movements and also colisions. Like in the curent state we cannot have precise things for multi player usage..
Rounding still could work, if you move first and then round the transform position vector3 after the movement is applied perhaps
Your answer
Follow this Question
Related Questions
Player flies up into the air when walking 3 Answers
Unity Physics Engine over Multi platform 1 Answer
Physics.Raycast Help 2 Answers
How to make a GameObject collide properly with an animated plane? 0 Answers
2D 360 degress platformer example needed 0 Answers