Redhair
1
When an object moves with translate method, I’d like to get flagged when the object passes through certain coordinate.
For example, I want to get flagged when z coordinate of moving object is 1.1.
It seems like coordinate values and too detailed(like 1.1739482627) to do any comparisons with.
Any suggestions?
Try this:
Vector3 previousPosition;
float flagPosition = 1.1f;
void Update () {
bool flag = false;
if((previousPosition.z > flagPosition && transform.position.z < flagPosition)||(previousPosition.z < flagPosition && transform.position.z > flagPosition)){
flag = true;
}
previousPosition = transform.position;
transform.position = new Vector3();//new value
}
Edit:
and if you don’t want get unexpected flag on the begin put this line in Start() function:
previousPosition = transform.position;