How do I force a positive-only sine

Get help using Construct 2

Post » 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
122
S
42
G
40
Posts: 846
Reputation: 27,994

Post » 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

Post » 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
122
S
42
G
40
Posts: 846
Reputation: 27,994

Post » Mon Nov 28, 2016 3:51 pm

abs(object.sine.value) should work too
Image Image
B
22
S
13
G
130
Posts: 869
Reputation: 67,816

Post » 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
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » 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

Post » 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.

https://www.google.ca/?q=y%3Dabs(sin(x))%2C+y%3D(sin(x)%2B1)%2F2#safe=off&q=y%3Dabs(sin(0.5x))%2C+y%3D(sin(x-pi%2F2)%2B1)%2F2
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » Mon Nov 28, 2016 8:16 pm

@Magistross
to much math for me, I'm outta here. :D
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


Return to How do I....?

Who is online

Users browsing this forum: Darth Crusher and 1 guest