Hi,
I’m just sharing here a good practice:
If you only need to compare lengths of some vectors, you can compare squared length of them using sqrMagnitude. Computing squared magnitudes is much faster: it only calculates x * x + y * y + z * z, instead of the square root of x * x + y * y + z * z.
float sqrMagnitudeBeforeMoving = (transform.position - targetPosition).sqrMagnitude;
transform.position += moveSpeed * Time.deltaTime * moveDir;
float sqrMagnitudeAfterMoving = (transform.position - targetPosition).sqrMagnitude;
if (sqrMagnitudeBeforeMoving < sqrMagnitudeAfterMoving) {
...
}