# Keep current cycle position of Sine while changing magnitude ? (rope swinging)

0 favourites
• 6 posts
From the Asset Store
Simplistic hyper-casual game with nature elements. Tap to switch between the 4 elements and reach a better score.
• Hello,

I'm trying to make a swinging rope so the player can catch it and swing around.

The rope starts with a low magnitude of 2 so it's gently swinging

When the player grabs it, its magnitude is increased to -80 (or 80 if the player is mirrored).

And I use set sine position to either 0 or 1 (depending on mirroring) so it starts at the middle.

Works fine with the low starting magnitude, but if the player catch the rope while its magnitude is much higher...(its magnitude decrease over time) then the cycle position 1/0 won't work as the player will be teleported to the middle.

How can I keep the current cycle position while increasing the magnitude ? Is it possible ?

• I think you’d want to pin the player to the rope, without changing the current sine value or magnitude. So if that’s a matter of changing how you vary the magnitude? To get a more useful suggestion you may have to post the events you’re using now.

• I'm sure, this can easily be done with asin() expression, this is basically a school-level math. The problem is, I don't remember it :)

So here is a workaround - change the magnitude gradually over a short period of time. You can do something like this:

``````Set newMagnitude=100
On every tick: sprite Sine set magnitude to lerp(self.Sine.magnitude, newMagnitude, dt*4)
or:
On every tick: sprite Sine set magnitude to min(self.Sine.magnitude+1, newMagnitude)
``````
• Thanks for your help guys !

The gradually changing magnitude helped but I still can't get it right... Can't figure out why it sometimes goes forward instead of backward (and some other weird moves), there might be something with positive/negative value but my (very low) math level is not helping at all..

If by any chance you want to give it a try, here is the C3p (r131 stable):

Basically, once the player grabs the rope, it gets a strong impulse to reach its top magnitude (80) - then it slowly loses its momentum to the initial magnitude (3)- unless the player gives it a little swing using left or right - or by jumping again on it.

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• I did it! Don't ask me how, but it works..

dropbox.com/s/8ae8h948w8jt1sa/SineRopeChangeMagnitude.capx

• Awesome work man :) Works perfectly (and it's pretty satisfying to use), thanks a lot ! :)

• 6 posts