Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

1 comment

0

put [SOLVED] at the title of your question since you found the solution

This discussion is preserved as it was. New answers, comments, and votes are closed.