# How do I force a positive-only sine

Get help using Construct 2

### » Mon Nov 28, 2016 7:12 am

Hi everyone,

If I assign the sine behavior to an object and have a Magnitude of 1, the sine will go all the way to 1, then all the way to -1 and so on.

What would be the best way to force it to go only from 0 to 1?
B
129
S
44
G
41
Posts: 857
Reputation: 28,485

### » Mon Nov 28, 2016 10:37 am

If you set the sine behaviour Movement field to "value only", you can then return a value between 0 and 1 in an action using the expression:

(object.sine.value+1)/2

You can then apply that expression to whatever variable you want the sine to be working on.

You can extend that formula to return a value between 0 an N:

N((object.sine.value+1)/2)
B
4
S
1
Posts: 3
Reputation: 276

### » Mon Nov 28, 2016 3:48 pm

Thanks, that's exactly what I was looking for!
Last edited by andreyin on Tue Nov 29, 2016 12:26 pm, edited 1 time in total.
B
129
S
44
G
41
Posts: 857
Reputation: 28,485

### » Mon Nov 28, 2016 3:51 pm

abs(object.sine.value) should work too
B
28
S
17
G
157
Posts: 892
Reputation: 81,757

### » Mon Nov 28, 2016 5:06 pm

abs(object.sine.value) is definitely not the same. You alter the sin wave in a most likely unwanted way.

What could work too is using (object.sine.value + object.sine.magnitude) to return a value between 0 and 2*magnitude.
B
80
S
33
G
27
Posts: 1,027
Reputation: 21,114

### » Mon Nov 28, 2016 6:01 pm

@Magistross why can't you just use abs(Sine.Value) and double the interval?
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

### » Mon Nov 28, 2016 7:09 pm

You can, but the curve won't be sinusoidal.

Here, you can use google to plot both equations.

B
80
S
33
G
27
Posts: 1,027
Reputation: 21,114

### » Mon Nov 28, 2016 8:16 pm

@Magistross
to much math for me, I'm outta here.
Anyways, thanks for explaining.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091