Do an action every tick for X seconds?

  • This is probably plain as day, but I am missing it.

    I want my PC to walk away from the wrong direction, so I start ignoring input and every tick simulate pressing left.

    How do I do this action for only 1 second?

    So "every tick" simulate control left "for x Seconds".

    If someone could point me in the right direction I would be greatful. But please don't tell me exactly how to do it, I learn better that way, just need a steer in the right direction.

  • The problem is right there in your logic: you can't do something for 1 second every tick. Every tick is usually every 1/60th of a second.

    If you want to do something for X seconds, you need to have a more specific condition, like "on keypress", "on key released" or "on collision"

  • This is probably plain as day, but I am missing it.

    I want my PC to walk away from the wrong direction, so I start ignoring input and every tick simulate pressing left.

    How do I do this action for only 1 second?

    So "every tick" simulate control left "for x Seconds".

    If someone could point me in the right direction I would be greatful. But please don't tell me exactly how to do it, I learn better that way, just need a steer in the right direction.

    This could work:

    Variable DisableControls = 1

    Every 1 seconds

    ..DisableControls > 0

    ... Subtract 1 from DisableControls

    ... Set controls disabled

    ..Else

    ...Set controls enabled

    Then you'd have another event where you define your walk left action.

    .. your event

    // walk scene starts

    .. DisableControls = 1

    .. //trigger your walk action

  • The problem is right there in your logic: you can't do something for 1 second every tick. Every tick is usually every 1/60th of a second.

    If you want to do something for X seconds, you need to have a more specific condition, like "on keypress", "on key released" or "on collision"

    I think you misunderstand me. If I want to have an AI move left, it has to be "simulating left" every tick to move smoothly. But how do I then get the AI/or a PC whose control is taken away from the player to stop after going left for 3 seconds?

    So to be plain, I want to make something simulate pressing down left for 3 seconds. How do I do this so it moves left for 3 seconds then stops?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So there isn't just an expression instead of "every x seconds" something like"

    "for 3 seconds" do this action...

  • So there isn't just an expression instead of "every x seconds" something like"

    "for 3 seconds" do this action...

    Nope, you could do it like I suggested, with timer variable.

  • > So there isn't just an expression instead of "every x seconds" something like"

    >

    > "for 3 seconds" do this action...

    Nope, you could do it like I suggested, with timer variable.

    Yeah thanks! I might do that! Seemed pretty straight forward. I just assumed there was an expression or something hehe.

    However in this case, I just put a "when collide with object stop moving" type dealie, because I wasn't running a fully featured group of AI events, but more of a scripted event.

    Thanks though! I appreciate everyones input.

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