# Sine - On Max magnitude reached?

Get help using Construct 2

### » Mon May 27, 2013 5:27 pm

Hi.

Im experimenting with the Sine behavior.

Take for example the 'Sine Behavior Types' project in Construct 2.

Take the sprite in the top left corner with UID 0.

How would YOU make that sprite pick a new random magnitude, every time it reaches the extreme of the current(As in, each time it goes to leftmost or rightmost side)?
B
10
S
3
Posts: 233
Reputation: 1,537

### » Mon May 27, 2013 5:59 pm

Leftmost and rightmost positions are respectively at cycle position 0.25 and 0.75. You could use this information to modify the magnitude at will, however, cycle position can't really be tested with such fixed values. You need to test greater than/lesser than and use a boolean to switch the active condition. Second, magnitude shouldn't be changed at those moments, because it'll totally break the behavior... (I just tried ) BUT ! Changing the magnitude at cycle time 0 and 0.5 (when the sprite is centered) should do what you want.

Here's the result : http://www.freewebs.com/johnwof/newRandomMagnitude.capxMagistross2013-05-27 18:00:11
B
80
S
33
G
27
Posts: 1,027
Reputation: 21,114

### » Mon May 27, 2013 6:16 pm

Yea, works awesome that way, thanks! ^^

One more question tho - Since the Magnitude is different, but the period is always the same, the speed of the movement varies a lot.

Do you happen to know any formula for period that would make it's movement Period consistent with the Magnitude?

As in, no matter how large of a magnitude you pick, the object wouldn't move any faster(in terms of pixels per second) across the screen?

I'm guessing it's just about figuring out the ratio between the default Magnitude/Period and applying that ratio to the Period depending on new value?Xionor2013-05-27 18:21:42
B
10
S
3
Posts: 233
Reputation: 1,537

### » Mon May 27, 2013 6:46 pm

Yup, you got it right ! I just re-uploaded the example with the implementation of such a ratio.
B
80
S
33
G
27
Posts: 1,027
Reputation: 21,114