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

0 favourites
  • 6 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • 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!

  • 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.

  • 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

    Check line of sight - Change to Shooting
    Is Hiding           - Wait 2
    
           Check line of sight - Fire
           Trigger once        - Wait 2
                               - Change to Hiding[/code:3qcekd1b]
    
    (EDIT: Formatting)
  • 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:

    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:

    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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Not firing in unison, use for each enemy condition.

    Edit: Looks great btw!

  • Noted!

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