Make enemy react with time sensor

Get help using Construct 2

Post » Fri Nov 23, 2012 12:09 pm


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.
Posts: 2
Reputation: 254

Post » Fri Nov 23, 2012 1:10 pm

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.
Posts: 64
Reputation: 4,014

Post » Fri Nov 23, 2012 1:16 pm

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.
Posts: 64
Reputation: 4,014

Return to How do I....?

Who is online

Users browsing this forum: dioking and 16 guests