Every random(3,8) sec--not working...

0 favourites
  • 5 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • Side view fighting game (basically), with Player and Enemy.

    For the enemy's in-game behavior, I want:

    Between 3-9 seconds while the enemy is playing "Idle" animation, the enemy attacks.

    My problem: The enemy attacks correctly, but ALWAYS on 3 second intervals--NOT randomly between 3 and 9 seconds. Where is my issue?


    Every random(3,9) sec.

    AttackType(Global Variable)=0

    Enemy anim = "Idle"


    Set AttackType = 1


    AttackType = 1


    Set Animation to "Attack1"

    Set AttackType = 0

  • I think the every X seconds event just doesn't get along with the random function. I'd suggest using this instead:

    Event 1:


    Enemy anim = "Idle"

    AttackType(global Variable)=0


    Wait random(3,9) seconds

    Set AttackType=1

    Event 2: unchanged

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • you could also set a global variable to the random(3, 9) and then do every globalVariable seconds, and set it to reset as you need (say after the attack set global variable random(3, 9)

  • i think that if you do a global variable for this, all your enemies will attack you at the same time. better use private variable for your enemies:

    start of layout: set enemy.timer to int(9-(random(6)))


    every enemy.timer seconds: kick player; set enemy.timer to int(9-(random(6)))

    int(9-(random(6))) - i think, this expression gives better results than just int(random (3,9))

  • This is very helpful, thank you all three!

    I had a feeling the random was simply not playing well the way I was using it, because I've used it successfully in other situations.

    I will try your suggestions very soon, and report back with solutions.

    Thank you!

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