You’re potentially going to have problems comparing floating point. Here’s why:
Floating (float) point imprecision:
Never test floating point (float) quantities for equality / inequality. Here’s why:
https://starmanta.gitbooks.io/unitytipsredux/content/floating-point.html
https://discussions.unity.com/t/851400/4
https://discussions.unity.com/t/843503/4
“Think of [floating point] as JPEG of numbers.” - orionsyndrome on the Unity3D Forums
I always use this pattern:
Smoothing movement between any two particular values:
https://discussions.unity.com/t/812925/5
You have currentQuantity and desiredQuantity.
- only set desiredQuantity
- the code always moves currentQuantity towards desiredQuantity
- read currentQuantity for the smoothed value
Works for floats, Vectors, Colors, Quaternions, anything continuous or lerp-able.
The code: https://gist.github.com/kurtdekker/fb3c33ec6911a1d9bfcb23e9f62adac4
You can see an example of it here in this project:
https://www.youtube.com/watch?v=BtT1N1lzFns
Specifically here, around line 99 where I set the desiredVisualsFacing
based on facing:
and then line 108 where it lerps towards. I prefer the lerp feel, but you could use MoveTowardsAngle instead.