0 Favourites

How do I jump enemy every radom second

  • Hello (excuse my english),

    How do I jump enemy every radom second with "for each instance" function.

    I tried that but it is jumping all at once or just one jump.

    http://joueralamaitresse.com/test/enemy_jump_random.capx

    Help me please.

  • Will the enemys all start/stop moving at once, as they do now (with 1 global variable for all) ?

    Or, will they (in your gamelogic) start/stop moving when they have a personal reason to do so ?

    It is a differend approach.

    A reason could be, when they see the player .....

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Hello (excuse my english), <img src="{SMILIES_PATH}/icon_redface.gif" alt=":oops:" title="Embarrassed">

    How do I jump enemy every radom second with "for each instance" function.

    I tried that but it is jumping all at once or just one jump.

    http://joueralamaitresse.com/test/enemy_jump_random.capx

    Help me please. <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    If I understood you correctly:

    Use timer behaviour (add it for the enemy object), set timer to random duration for each enemy. On timer expiration do jump and then set new timer with new random duration.

    I personally avoid putting every X seconds inside a for each object loop, because loops need to finish their actions within one tick/frame. Timer behaviour was made for such things (that need to be executed across multiple frames/ticks) and it works great.

    Please see attached capx (I decided to go with 1-3 seconds between jumps, also disabled your events for jumping):

    https://www.dropbox.com/s/e5igcja8182g9 ... .capx?dl=1

    Note: this will only work if no new enemies are created after layout start. If new enemies are created while it is running, you would also need to add an "on enemy create" event to set the timer for that new enemy.

  • It's exactly that !

    my code seems logical but does not works. (Logic internal function..."for each instance" ?)

    your solution works very well.

    Thank you very much.

  • my code seems logical but does not works. (Logic internal function..."for each instance" ?)

    your solution works very well.

    .

    No problem. However you have to realize that your events set the every random seconds condition every engine tick (so every frame). Enemy_go=1 was true every tick.

    The event would set it once and then overwrite it in the next frame up to 60 times a second, as a new for each loop runs every tick. Also once it finished the for each enemy loop it should no longer track the every random seconds, as the tracking exists only within the for each loop and ceases to exist once the loop finishes. That is why I wrote that I was surprised that it even worked for one enemy at all.

    As timer behaviour exist outside of events (just like other object properties and variables) it works in such cases.

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