Forum rules - please read before posting.

In the code there are a lot of float comparisons using the equal operator i.e. movespeed == 0f Why?

I took a look at some of the scripts in AC and saw that there where some float comparisons using == or != operator. So then I ran a Code Inspection in Rider and it found about 120 cases where floats are compared using an equal operator. I have been taught that this is not a good code practice since it can cause false negatives, because floats are slightly imprecise. Shouldn't you use Mathf.Approximatly method or something similar like Math.abs( a - b) < float.Epsilon. Or am I missing something? Does the C# compiler fix this automatically?

Comments

  • edited May 2018
    Welcome to the community, @ashwinFEC.

    Thank you for pointing this out.  While in most cases this is actually fine (due to only being related to Editors etc), it is indeed best practice to use approximations.  I shall remedy this in the next release.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.