- Home /
Why is the if condition returning true ?
I want to check if the Y position is changing or not for the player and the enemy. If it as changed in the frame I want it to return true and if it didn't i want it to return false. I round because the enemy's position altern between 0.8 and 0.800001 . When I tried to do Mathf.Round(transform.position 100)/100 and I compare is to the enemyOldPosition with I assigned using enemyOldPosition = Mathf.Round(transform.position 100)/100, but it says its not equal. I tried to check Debug.Log(enemyOldPosition - Mathf.Round(transform.position * 100)/100) and it returned 1.192093E-08.
 void Update()
 {
 if(Mathf.Round(player.transform.position.y*100)/100 == oldPosition)
         {
             isChangingY = false;
             oldPosition = Mathf.Round(player.transform.position.y*100)/100;
         }
         else
         {
             Debug.Log(oldPosition - Mathf.Round(player.transform.position.y*100)/100);
             isChangingY = true;
             oldPosition = Mathf.Round(player.transform.position.y*100)/100;
         }
         
         
         if(Mathf.Round(transform.position.y*100)/100 == enemyOldPosition)
         {
             enemyIsChangingY = false;
             enemyOldPosition = Mathf.Round(transform.position.y*100)/100;
         }
         else
         {
             Debug.Log(enemyOldPosition - Mathf.Round(transform.position.y*100)/100);
             enemyIsChangingY = true;
             enemyOldPosition = Mathf.Round(transform.position.y*100)/100;
         }
         
     }
script is placed on enemy and they both have rigidbodies
Your answer
 
 
             Follow this Question
Related Questions
Take final position after a force applied to a GameObject 1 Answer
object return position not always the same when I define return position 1 Answer
Use GameObject's global position instead of local position 3 Answers
How to edit one axis of the transform position 1 Answer
how to CORRECTLY position and rotate a gameobject in unity 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                