If you are only comparing distances, it might be good to know that calculating square root is kind of expensive operation, since up to my knowledge it always involves a lot of calculation. Might be using newton method or something, but regardless it is a lot more expensive to calculate square root than sum or multiply. Same goes for all other numbers that are represented by taylor series like sin, cos, etc.

Code: Select all

```
local tresh = 3
local dist = math.sqrt(a*a + b*b)
if dist < tresh
print("within")
end
```

Code: Select all

```
local tresh = 3
local dist = a*a + b*b
if dist < tresh*tresh
print("within")
end
```

After saying that I have heard that.: "Premature optimization is the root of all evil." And if you calculate one square root per update loop it probably doesn't matter, but if you do a lot of them it might actually have a minor impact on performance.

Edit: Oh and if you do not care in which order the items are in a table, and you do have a lot of them. Swapping the object that you want to remove with the last object, then decreasing the loop counter by one and removing the last object is a lot faster than removing from a middle of a table. This is since the table tries to maintain the order, and moving every single object in the table by one might cause some slow downs in case you have A HUGE table.