Hey, following a tutorial i stumbled across this code:
const float thresholdUpdate = 25f;
const float sqrThresholdUpdate = viewerMoveThresholdForChunkUpdate * viewerMoveThresholdForChunkUpdate;
yada yada yada
void Update() {
Position = new Vector2 (viewer.position.x, viewer.position.z);
if ((PositionOld - Position).sqrMagnitude > sqrThresholdUpdate) {
PositionOld = Position;
UpdateStuff ();
}
}
Now, this all works fine and dandy, but why does he square the values?
can’t we just use both the values not squared with the same result and avoid a whole lot of math in the process?
also, regarding if statement.
if i have a statment with 2 conditions and it checking for both to be true, if the first one is false will the second will still be calculated or skipped?
and is this true also for checking for either ( con1 || con2 ), if the first one is true will the system check the other one aswell?