Z
Z
Zimaell2020-12-27 18:09:43
Unity
Zimaell, 2020-12-27 18:09:43

How to round transform.position?

I am moving an object to the given coordinates, as soon as it reaches them, the action is triggered

Vector3 TPos;
void BlockSwap(){
  if(TPos != obj.transform.position){
    Debug.Log(TPos.x +" != " + obj.transform.position.x);
    MooveColor.transform.position = Vector3.MoveTowards(obj.transform.position, new Vector3(TPos.x, TPos.y, 0), 5f * Time.deltaTime);
    }else{
      Action ="";
      obj.transform.position = this.transform.position;
      }
  }

but the condition doesn't work so the numbers don't exactly match, for example
-0.4800001 != -0.4799805

that is, in fact, you need to either round y and x, or do it differently, tell me how to do it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2020-12-27
@Zimaell

Compare fleets as it is customary to compare fleets - with a certain tolerance.
Directly in the unit there is an Approximatly method for this. But it can be very accurate - so just compare the modulus of the difference with some epsilon

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question