How would I invert the magnitude value?

Hello there!

I’m currently working on a horror game which will have a spirit box like item inside (similar to Phasmophobia). I have got the distance between 2 parts using .Magnitude already but the further away the part is, the bigger the value.

I don’t want this to be the case as I want the value to increase as the parts get closer.

Anyone know how to do this?
Thanks in advance.

1 Like

You could do a reciprocal function. A number (for example 1) divided by the magnitude.


You can use startMagnitude - currentMagnitude, the value will increase as they get closer

1 Like

Yep like @Galactiq and @Jxl_s said you can use those formulas:

To make sure you understand what you are doing its best to plot it out on desmos like in this example here which uses @Jxl_s formula which is linear.

1 Like

For clarification, my suggestion would be a rational function, whereas the suggestion made by @Jxl_s is linear. Just keep those in mind when deciding which is best for your need.

1 Like

What would the start magnitude be compared to the current magnitude, or is it just flying over my head

The actual mathematical answer to this post is currentMagnitude^-1, because you’re asking for its inversion.

The inverse of currentMagnitude is currentMagnitude^-1 (remember to check if currentMagnitude is zero!), you can then multiply it by a factor if you believe it’s too low.

1 Like