# Normalize number to between 0 and 1

Get help using Construct 2

### » Wed Mar 27, 2013 1:38 pm

Hey all,

I've been a member for a while - but this is my first forum post!   (Haven't needed to ask anything, since this community has answered almost everything for me!)

My question - If i have a range, like say 234 - 1250, assuming 1250 is the max and 234 is the minimum. How could I take a third number, say Sprite.Physics.VelocityY and normalize the number to be between 0 and 1?

I realize this is more of a math question than anything, but I'm curious if there is a Contruct-y way of doing this?

If the answer is/was simple, then forgive me :P
B
8
S
2
Posts: 12
Reputation: 1,159

### » Wed Mar 27, 2013 2:12 pm

Not sure what you need, but I'd try velocity *0.1
B
163
S
48
G
100
Posts: 7,440
Reputation: 72,002

### » Wed Mar 27, 2013 2:24 pm

I see. Ok, well - clamp seems to only give either upper value or lower value depending on how close the variable is to either.

lerp - well, still trying to wrap my head around lerp (and I suspect is probably what I need to use - still tinkering with it)

but essentially, this is what I am trying to figure out:

I have a character falling and falling. Velocity of the fall i have set to an upperbound of 1200. I have particles that trail behind (speed lines) but I want the opacity to increase as the rate of descent increases. Since opacity is between 0 and 1 - i'm looking for a way to convert my numbers (velocity, upperbound) to a value between zero and 1.

Newt - thanks for the suggestion, but I have other uses and would like a more normalized number.

my brain asplodes when looking at things like this: http://stn.spotfire.com/spotfire_client_help/norm/norm_scale_between_0_and_1.htm
B
8
S
2
Posts: 12
Reputation: 1,159

### » Wed Mar 27, 2013 2:43 pm

I think I've got it:

minBound is the lower number, maxBound is the higher

(variable - minBound) / (maxBound-minBound)

Booyeah!
B
8
S
2
Posts: 12
Reputation: 1,159

Return to How do I....?

### Who is online

Users browsing this forum: Yahoo [Bot] and 15 guests