How do I make "SINE" movement random but always ...

0 favourites
  • 7 posts
From the Asset Store
Always Fashion
$16.15 USD
15% off
This Girls Game allows young fashionistas to develop their taste and skills as a fashion designer.
  • Hello Scirra people.

    I have a object that is moving with the Sine object.

    I want it to go back and forth.

    But in the same speed. currently the only way I know how to make it work is with sine is to have a random magnitude, but that makes the object move faster aswell.

    is there a way to always make a object move at the same speed but random length?

    For example.

    It always have a 50 magnitude.

    But first time it moves

    <------>

    Next sine, it moves

    <-------------->

    (random length)

    But always in the same speed.

    how do I achieve this?

  • You have to calculate the period.

    Period

    The duration, in seconds, of one complete back-and-forth cycle.

    Speed = distance / time

    So time (period) = speed * distance.

    Now distance is in fact the magnitude.

    The speed is a constant, thats is what you want, it is some value you choose.

    So,

    Set magnitude

    Set period to speed * magnitude

    What i dont know is kinda, when to do it. If you change it middle in the cycle, i suppose it will go weird.

    I suppose you have set a new cycle when the expression CyclePosition returns zero.

    I idid not test this, just writing whats in my head.

  • Still need help on this!

  • Bumping this thread.

    Is there maybe a other method?

  • Do you need to use SINE movement?

    If it's always needing to be the same speed, but vary the distance it travels... it would be easier to create a custom movement for it.

    Use bullet behaviour with a set speed, and randomly pick a distance for it to move from it's starting point. Create two instance variables for it's starting spot (X and Y) then create two more for it's destination point (X and Y) and just add or subtract a random value from the destination points... then set the motion towards those destination points.

    It's probably easier than trying to mess with over-riding the sine behaviour.

    ~Sol

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Do you need to use SINE movement?

    If it's always needing to be the same speed, but vary the distance it travels... it would be easier to create a custom movement for it.

    Use bullet behaviour with a set speed, and randomly pick a distance for it to move from it's starting point. Create two instance variables for it's starting spot (X and Y) then create two more for it's destination point (X and Y) and just add or subtract a random value from the destination points... then set the motion towards those destination points.

    It's probably easier than trying to mess with over-riding the sine behaviour.

    ~Sol

    I can use whatever works, how would the code look if I had bullet behavior that changed directions like Sine movement?

    • Send the bullet flying forth at (fixed speed)
    • Wait (random time)
    • Sends the bullet flying back at (fixed speed)
    • Wait (twice the previous time)
    • Start over
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)