I am trying to check if a platform has reached a specific distance relative to its starting/original position. For achieving this objective I used the following code snippet but it doesn’t seem to work.
float maxMoveValue = 10;
float originalXpos = transform.position.x;
if(transform.position.y == originalYpos + maxMoveValue)
{
maxVertical = true;
}
I have also tried it this way:
Vector3 originalVector = new Vector3(originalXpos + maxMoveValue, 0f, 0f);
if(Vector3.Distance(transform.position, originalVector) ==0 )
{
maxHorizontal = true;
}
But this also doesn’t work.
What am I doing wrong?
EDIT:
I have found the culprit but don’t know why is this happening and what can be the solutioin?
Problem:
Actually the float addition is not working properly. if a = 22.3519; & b = 10; result = a +b; is resul = 22.35190
Regards