How do I can change sine movement for a period of time?

0 favourites
  • 11 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • Hi, I have a problem, I'm not very smart, you can not help me with that. But you can answer my doubt xD

    I have a layer ??that repeats the creation of an object (with sine behavior in horizontal movement). But I want in the second 15 the object to stop having horizontal movement, and then change to vertical, and then in the second 30 change to an angle.

    Tried adding event> system> compare time 15.

    With action of the object in set sine movement vertical, but only works for the creation of 1 object in the second 15, and not the following ones.

    Thanks for the help.

  • Add Timer behavior to your object.

    On object created -> Object start timer "ChangeMovement" for 15 seconds (Regular)

    Object on Timer "ChangeMovement"

    ...Object: Sine compare movement is Horizontal -> Object: Sine set movement to Vertical

    ...Else -> Object: Sine set movement to Horizontal

  • Add Timer behavior to your object.

    On object created -> Object start timer "ChangeMovement" for 15 seconds (Regular)

    Object on Timer "ChangeMovement"

    ...Object: Sine compare movement is Horizontal -> Object: Sine set movement to Vertical

    ...Else -> Object: Sine set movement to Horizontal

    Hi, thanks for the answer. But is not working ( sorry for being slow I'm testing before buying the license)

    I obviously did something wrong

  • No, it's all correct. I did the same and it works for me.

    Maybe there is something else in your code that breaks it.

    Did you set "active on start=yes" for Sine?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • No, it's all correct. I did the same and it works for me.

    Maybe there is something else in your code that breaks it.

    Do you have "active on start=yes" for Sine?

    Yes, is active on start.

    Actually, i am testing with the example of flapy that brings construct 2, because i think is a good way to learn about event and actions with behaviors. Here is a bigger image

  • I still don't see any errors.

    Could you save your project as a single file (capx) and share it?

  • I still don't see any errors.

    Could you save your project as a single file (capx) and share it?

    Of course sir, here is it uploadfiles.io/euzfs

  • The pipes are moving too fast and disappear from the screen before they change Sine movement.

    But now I understand that you wanted to change movement at the moment the sprite is created, not 5 seconds after it was created.

    I'm guessing you want to create pipes with Horizontal movement for 5 seconds, then with Vertical movement for 5 seconds and so on?

    You can do this with a single variable, say verticalMovement=0

    Every 5 seconds
        verticalMovement=0  -> set verticalMovement=1
        Else -> set verticalMovement=0
    
    Every 1 second ->    Create object bottomPipe
        verticalMovement=1 -> bottomPipe Set Sine movement to Vertical
    [/code:2h6s54w7]
  • The pipes are moving too fast and disappear from the screen before they change Sine movement.

    But now I understand that you wanted to change movement at the moment the sprite is created, not 5 seconds after it was created.

    I'm guessing you want to create pipes with Horizontal movement for 5 seconds, then with Vertical movement for 5 seconds and so on?

    You can do this with a single variable, say verticalMovement=0

    > Every 5 seconds
        verticalMovement=0  -> set verticalMovement=1
        Else -> set verticalMovement=0
    
    Every 1 second ->    Create object bottomPipe
        verticalMovement=1 -> bottomPipe Set Sine movement to Vertical
    [/code:30hrbmcx]
    

    It works but it is not what I wanted. I will explain myself better:

    Being an event "every x seconds" means that it alternates the movement every x seconds from horizontal to vertical, and vertical to horizontal.

    At the beginning I said about the "compare time" event in 15 seconds,

    because I wanted when the player plays from the second 0 to the 14 had pipes with their default movement (horizontal). Then, when he reached the second 15 in the game, the pipes get the vertical movement permanently. Finally, when he's 30 seconds, the pipes get Angle movement permanently, and maybe a new movement on the 45, 60...

    This, would give a feeling that the player is advancing between levels, but in reality it will be forever in the same layout.

  • Pipes in this game only exist for about a second, then get destroyed. So we are talking about creating new pipes, no need to change movement for existing pipes.

    Code example that I gave changes Sine movement to vertical for all newly created pipes after 5 seconds of playing.

    You can modify it like this:

    variable MovementType=0
    
    Every 15 seconds
        Add 1 to MovementType
        MovementType=4 -> Set MovementType=0   //  this will reset back to 0 after 60 seconds
    
    Every 1 second ->    Create object bottomPipe
       // no need to add "MovementType=0 -> set movement to horizontal", because that's the default movement
        MovementType=1 -> bottomPipe Set Sine movement to Vertical
        MovementType=2 -> bottomPipe Set Sine movement to Angle
        MovementType=3 -> bottomPipe Set Sine movement to Size
    [/code:d6jam51w]
     
    This will do what you want - first 15 seconds pipes will have horizontal movement, next 15 seconds vertical, next 15 seconds angle, then size, then back to horizontal.
    
    Another way to do this is to add 4 Sine behaviors to the sprite, one for each movement type (rename them to SineHoriz, SineVert, SineAngle, SineSize). Then by enable/disabling them with events you can create combinations of movements, say horizontal+angle, vertical+size etc.
    
    One more thing - it's better to use Timer behavior instead of "Every X second".  With Timer you have better control, you can stop it, restart, check remaining time etc.
  • Thanks for all your answers Doptrix. I understand that my main problem was not using variables for the allocation of movement, by not using them, the pipes obtained double movement causing bugs. But thanks to your answers with comments, I understood how useful it is to combine variables with assignment events, to avoid bugs.

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