How do I get this Line of Sight loop to work?

Get help using Construct 2

Post » Sat Feb 20, 2016 2:18 am

Image

What I'm trying to achieve is as follows:
  • Enemy has LOS on player
  • Enemy waits 2 seconds then switches to "Shooting" state
  • Enemy eneters "Shooting" state and fires at player
  • Enemy wait another 2 seconds and goes back to "Hiding" state

This would then loop if the enemy had LOS on the player. Hide 2 seconds, Fire for 2 seconds.

Problem is that the enemy starts Hiding, enters Firing state and fires once, and then stays in that state and doesn't fire.

I feel like this is a super basic thing that I'm missing. I'm familiar with doing "Else" conditions but that doesn't seems right in this case. Appreciate any help!
B
42
S
11
G
1
Posts: 264
Reputation: 3,299

Post » Sat Feb 20, 2016 3:44 am

Wait doesn't prevent your second event from going off every tick.

So in that 2 seconds you are waiting, that second event will keep running, and keep queuing up the action to set state to shooting. After 2 seconds is up, for the next two seconds it will keep setting SpecificState to "Shooting"

Your third event only runs once, right when the first 2 seconds is up. It shoots and sets the state to hiding. But the previous action was queued up for 2 seconds more and keeps setting the state back to Shooting. Since your third event has trigger once, you never get to set SpecificState back to hiding.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Sat Feb 20, 2016 3:52 am

Sorry I didn't answer your question of how to get it to work, I only told you why it doesn't work =P

Not sure if this is the solution, but try changing the variable before the wait, and use sub events

Code: Select all
Check line of sight - Change to Shooting
Is Hiding           - Wait 2

       Check line of sight - Fire
       Trigger once        - Wait 2
                           - Change to Hiding


(EDIT: Formatting)
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Sat Feb 20, 2016 3:54 pm

@oosyrag Thanks for the input! I tried you solution but unfortunately it didn't work. However, you explanation was perfect and made me realize the huge mistake I was making: not using a subevent. So thanks for that!

I was able to make it work with the following code:
Image

It's kind of dirty with the "Every 4 seconds..." containing two "Wait" actions in it, but it works! Also tested it with multiple enemies and it works fine so far. Gif of action with filler enemy art:
Image

I would like to add a 'random' value in there so they aren't firing in unison but that isn't a priority right now :D
B
42
S
11
G
1
Posts: 264
Reputation: 3,299

Post » Sat Feb 20, 2016 3:57 pm

Not firing in unison, use for each enemy condition.



Edit: Looks great btw! :)
Last edited by oosyrag on Sat Feb 20, 2016 5:52 pm, edited 1 time in total.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Sat Feb 20, 2016 4:05 pm

Noted!
B
42
S
11
G
1
Posts: 264
Reputation: 3,299


Return to How do I....?

Who is online

Users browsing this forum: atmas, engin20020, gamecorpstudio, rbailey83, tarek2 and 25 guests