How do I make the sin wave vary in speed?

0 favourites
  • 8 posts
From the Asset Store
This kit includes the finished mp3 loop, the beat wave file, the lead wave file, and the Sub wave file.
  • Ive got a platform that goes up and down following the sin behavior and adding a certain magnitude.

    I've got the platform atm moving in a vertical motion but i want to make it vary in the speed.

    Any advice for this problem?

  • Reduce the period. Period is how long it takes to do 1 full cycle, so a smaller period will make it faster

  • Ah i should've rephrased that. I mean to make the speed of it be random. slow then fast etc

  • In you event sheet add something like

    every X seconds -- set sine period to Sprite to random(range required)

    or, maybe better ?

    every X seconds -- set sine period to Sprite to Sprite.Sine.Period+random(4)-2 (which will alter the period by +/- 2 seconds

    you might also want to set some limits so it doesn't get too fast/slow

    (not tested)

  • I don't use the built-in behaviors, so this is how I would do it.

    One way to write the wave equation is:

    D(x,t) = A sin(kx - wt + [theta])

    where w = 2(pi)f

    D is the displacement from the center, k is the spring constant, x is the x position on the wave, w is [2*pi*f], f is the frequency, t is the time, and theta is the phase angle.

    Since we're only concerned with one spot on the wave and not the entire thing we can let theta be zero and x be pi/2 (the maximum of a sin wave). However, if you had multiple objects you wanted to randomly wave together but not in perfect sync the easiest way to accomplish this would be by playing with the phase angle.

    Now, for the behavior you asked for, I think the easiest approach would be to vary the spring constant k and not the time t. All you would need to do is solve the wave equation on every frame (remember to use a proper delta-time value and calculate the current time rather than just counting frames) and move your object to whatever displacement you come up with. When you want to change how fast it's moving you can change the spring constant k value (which isn't so constant in this case....) and it'll start moving at the new speed on its own.

  • now tested...

    (latest beta can be found at the bottom of most pages)

  • Hey guys thanks for the replies. All posts were helpful!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Another question RamPackWobble, Is it possible to not have a range of random values? ie instead of 1-5 be its random between 1, 4, 5 or is this restricted for the clamp function?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)