Make enemy react with time sensor

  • Greetings!

    I was trying to develop a small A.I. for an enemy. The idea is having an invisible sprite playing as sensor, so when the player is overlapping it for more than 2 seconds, the enemy related to that sensor changes it's animation and tries to smash your character.

    I was wondering how do I set a timer just for that character, so it can run with this logic:

    -Set object timer to 0.

    -When player is overlapping sensor, the object timer starts.

    -If time = 2 (sec.) then "attack" attribute activates, and after completing the attack, it will return to 0 and set the animation to a non-attacking behaviour.

    -If player is not overlapping sensor, set object timer to 0.

    -Else, keep the regular animation.

    Something like that. The idea is that, in a platformer, you can run through that enemy without getting damage, except if you stay near it for 2 seconds. You know, like a small trap that waits a little bit.

    Maybe it can be done by the "wait" option, but I don't know how to set it up exactly.

    Maybe there's another way to program time-controlled reactions for the characters, but I don't know. Do you think it can be done?

    Thank you for any help you can give me.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • According your description, I thought you already have the problem figured out?

    My way of doing it by using instance variable.

    1)Setting instance variable on the enemy, name it firing, put it's value to 2.

    2)when playerbox is overlapping sensor ,substract dt from firing.

    3)when firing less or equal to 0, spawn "atk hitbox".

                                      set firing to 2.

    4)when playerbox is not overlapping sensor, set firing to 2.

    the attacking part:

    5)when playerbox is on collision with "atk hitbox" substract HP from playerbox.

  • tips:

    1)I prefer setting player HP as a global variable, as I can bring it across layout.

    2)It is better to damage system into a group.

    Eg. create a family of "atk hitbox", since you probably have more than 1 type of enemy, which spawn different attack.

    and then create a family variable call "atkdamage"

    so, you can simply write:

    For each family"atk hitbox"

    Family "atk hitbox" on collision with playerbox, playerbox substract atkhitbox.atkdamage to HP.

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