Im working out the distance between two objects, sometimes its a negative number, is there a function to remove the negativeness from a number, e.g. so -10 = 10.

Thanks

Im working out the distance between two objects, sometimes its a negative number, is there a function to remove the negativeness from a number, e.g. so -10 = 10.

Thanks

Have a look at Mathf.Abs. It’s the absolute value.

2 Likes

The signum function in Mathf

thought if you get negative distances your code is totally borked.

A distance can by definition never be negative and the reason is simple: Distances are calculated with ^2 and with sqrt, neither operation is able to have a negative result within the reel numbers, only complex numbers have the possibility to be negative with those operations.