Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[SOLVED] How do I convert a number between 0 and 1 to a number between -1 and 1?

Asked by 1 year ago
Edited 1 year ago

I am using the mouse position for a script but the value is between 0 and 1. This means that the center of the screen is 0.5,0.5. The top left is 0,0. The bottom right is 1,1. I need to change these to be values between -1 and 1. So the center would be 0,0. The top left would be -1,-1. The bottom right would remain 1,1. How can I do this?

1 answer

Log in to vote
0
Answered by 1 year ago

I found a solution to my problem

    x = (x * 2) + -1
    y = (y * 2) + -1

This could also be written as

x = (((x - OldMin) * (NewMax - NewMin))/ OldMax - OldMin) + NewMin
y = (((y - OldMin) * (NewMax - NewMin))/ OldMax - OldMin) + NewMin
0
put [SOLVED] at the title of your question since you found the solution T3_MasterGamer 2189 — 1y
Ad

Answer this question