help with enemy shoot bug?

0 favourites
  • 3 posts
From the Asset Store
Be discreet and rescue your friends from behind enemy lines.
  • Okay so basically I want it to pick the enemies (bulbasaurs) that are on screen AND have instance variable "time" less than 0, then out of those, pick a random one, and set its "time" to 100. When "time" reaches 99, play it's attacking sound. When "time" reaches 25, shoot at the player, and shoot again when "time" reaches 13. time's initial value is negative and it should be negative if the enemy isn't shooting or wasn't picked. However as you can see in the video here, sometimes they play the attacking sound twice overlapping, and shoot two bullets at the exact same time. How can I fix this?

    The reason I am using families is because say if there's two different species of pokemon on the screen, I want a random one of any of them to set "time" to 100, but depending on the enemy, I want it to make a different sound and/or shoot a different bullet.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It has to do with how events work.

    Event 8 will be tested every tick and will execute each time it is true.

    So since you're changing the value of time only once every 0.01 second that renders the event 8 true twice in a row, hence playing twice the sound.

    To correct it add a system condition "Trigger once while true".

    It's about the same for event 9, but you may have to split it into two events to have the second shoot also happening.

    Finally you might want to also look into the "Timer" behavior.

    Also a note for the next time you ask for help it might be easier to provide your capx rather than a video of the issue, since it allows us to look directly in the code and potentially provide a corrected capx back. Attach it to your post.

  • It has to do with how events work.

    Event 8 will be tested every tick and will execute each time it is true.

    So since you're changing the value of time only once every 0.01 second that renders the event 8 true twice in a row, hence playing twice the sound.

    To correct it add a system condition "Trigger once while true".

    It's about the same for event 9, but you may have to split it into two events to have the second shoot also happening.

    Finally you might want to also look into the "Timer" behavior.

    Also a note for the next time you ask for help it might be easier to provide your capx rather than a video of the issue, since it allows us to look directly in the code and potentially provide a corrected capx back. Attach it to your post.

    Thanks so much, it appears to be working right now! I am really glad it was a simple fix. But without your help I probably would not have thought of it.

    The reason I posted a video was because I thought it would be helpful to SEE the bug, since it doesn't always happen very often when I play the game. I thought between that and the screenshots it would be enough. And since you were able to help me, it seems like it was.

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