- Home /
(Magnitude of vector)*x SHOULD EQUAL magnitude of (vector*x)
(Velocity is a vector3)
velocity*=rayHit.distance/velocity.magnitude;
print(velocity.magnitude==rayHit.distance);
These two lines of code should ALWAYS print true, shouldn't they? I guess not, because I get false sometimes. Anybody know why?
Answer by Kiloblargh · Apr 08, 2014 at 12:22 AM
You can't ever count on any float to == any other float, that's just how it is when you are working with float values. You should check to see if the absolute value of one minus the other is less than .0001, if so, consider them equal.
Or you can use this:
Mathf.Approximately (velocity.magnitude,rayHit.distance)
Your answer
Follow this Question
Related Questions
What's the difference between print() and Debug.Log() 1 Answer
'print' not giving the correct rotation.y value 1 Answer
I want to print an obj/fbx object when a button is clicked 1 Answer
How can I manage that a 3dtext show date? 1 Answer
How to format numbers for print()... is javascript different to C? 1 Answer