How do I fire weapons with multipul barrels

0 favourites
  • 6 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • Hi everyone,

    So I am looking for a bit of advice on firing weapons with more than one barrel - specifically spawning projectiles and animating the weapons.

    For example, I have a weapon with two barrels. I would like to alternate spawning the projectile at each barrel and to know which barrel is firing so I can animate it.

    My current projectile system attempts to emulate swapping barrels but it is visual only and I cant control the order in which the barrels fire - therefore I can't animate them accurately.

    http://i.imgur.com/dq0lMWK.png

    Any advice is greatly appreciated.

  • I guess you could go the other way around - create an animation of the ship shooting with alternating barrels, then check the current frame. If frame is 5 (for example) spawn a bullet from the left barrel. If it's on frame 11 - spawn from the right barrel.

  • https://www.dropbox.com/s/hz5ai8rr2cl5o ... .capx?dl=0

    Use image points and toggle states, or an incrementing counter.

  • Thanks for the input guys!

    dropbox.com/s/hz5ai8rr2cl5oa0/alternate.capx

    Wow that is an incredibly elegant solution to my example, thank you very much oosyrag. Sorry to ask more of you, but I've clearly not had enough coffee today - how would you expand that system to include more barrels, 3 or 4 or 5 say.

    I guess you could go the other way around - create an animation of the ship shooting with alternating barrels, then check the current frame. If frame is 5 (for example) spawn a bullet from the left barrel. If it's on frame 11 - spawn from the right barrel.

    Thats a good suggestion too, thank you but I'm always hesitant to trigger things on frame because I've found it to be notoriously unreliable for some reason!

  • Wow that is an incredibly elegant solution to my example, thank you very much oosyrag. Sorry to ask more of you, but I've clearly not had enough coffee today - how would you expand that system to include more barrels, 3 or 4 or 5 say.

    Use an incrementing variable. So after each shot, add one to that variable, and use that to chose imagepoint, animations, ect... After it reaches the number of turrets, reset it back to 1. Remember imagepoint 0 is reserved for the origin). Or, you can do variable+1 when spawning from imagepoints.

    A fancy way of doing this is with a conditional operator:

    Assuming you have one imagepoint per barrel, and are not using imagepoints for anything else on that object...

    Upon firing, set ActiveBarrel to "ActiveBarrel<Object.Imagepointcount?Object.ActiveBarrel+1:1"

    This says "If the ActiveBarrel variable is less than the total number of imagepoints, then add one to ActiveBarrel. Otherwise, set ActiveBarrel to 1."

    This will cover any number of imagepoints you decide to add, and cycle through them one at a time.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • > Wow that is an incredibly elegant solution to my example, thank you very much oosyrag. Sorry to ask more of you, but I've clearly not had enough coffee today - how would you expand that system to include more barrels, 3 or 4 or 5 say.

    >

    Use an incrementing variable. So after each shot, add one to that variable, and use that to chose imagepoint, animations, ect... After it reaches the number of turrets, reset it back to 1. Remember imagepoint 0 is reserved for the origin). Or, you can do variable+1 when spawning from imagepoints.

    A fancy way of doing this is with a conditional operator:

    Assuming you have one imagepoint per barrel, and are not using imagepoints for anything else on that object...

    Upon firing, set ActiveBarrel to "ActiveBarrel<Object.Imagepointcount?Object.ActiveBarrel+1:1"

    This says "If the ActiveBarrel variable is less than the total number of imagepoints, then add one to ActiveBarrel. Otherwise, set ActiveBarrel to 1."

    This will cover any number of imagepoints you decide to add, and cycle through them one at a time.

    Hi Oosyrag,

    Wow what an excellent solution - before I saw your reply I had tried an incrementing variable system and while it worked it was no where near as simple and clear as your conditional operator suggestion. Thank you for not only providing a superb solution - but also taking the time to explain what the condition operator was doing, I appreciate it very much!

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