How do I make a multi-bullet?

0 favourites
  • 8 posts
From the Asset Store
Buildings - Isometric view - PNG transparent - multi styles, multi fonctions buildings
  • One of my power-ups is a fireball that fires a set of 3 projectiles in a fan.

    How do I achieve this in the event sheet?

    I want to spawn 3 projectiles, all on the same key press, and have them fan out in different directions.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • At the point where you want to spawn the three bullets, add this:

    Repeat 3 times [condition]
           -> Create object "fireball" [action]
           -> "fireball": set angle to: -20+loopindex*10[/code:20jmc0tt]
    
    This will spawn three fireballs, one at the angle -10, one at 0 and one at 10.
    
    If you want something different, just replace the second action with this formula:
    [code:20jmc0tt]"fireball": set angle to: ([highest angle you want] minus [angular difference between fireballs]) +loopindex * [angular difference between fireballs][/code:20jmc0tt]
    
    If you need more help, just send me your .capx or post the context of those fireballs, like angles and stuff.
  • Thanks, randomly! But I am so new to this that I really can't comprehend what I'm supposed to do with the code you typed above! Here is the code I have so far...

    -------------

    Keyboard | On SPACE pressed --> Player | Spawn FIREBALL on layer 1 (image point 1)

    -------------

    Where do i put the "Repeat 3 times" condition? Where do I find that condition; under System, player, or fireball?

    What is

      ? What is this multiply sign
    • ? Where do I put those? What is a +loopindex and what does it do? Sorry for my lack of understanding.
  • Whoopsiewhoo, that

      and
    • was a formatting fault by me. Keep forgetting that BBCode doesn't work in code.. Anyways, set it up like this:
      Just try it out, see if it suits your needings and if you need to modify the angle, just post it. :) EDIT: Should look like this:
  • AWESOME SAUCE! It worked. Thanks, randomly!

    One more quick question if you don't mind... can you help me understand how the angles work? What if i wanted the center fireball to shoot at 0 degrees, and the other two to be 30 degrees distance from it?

    In one of your above answers, you said that the -20 is the highest angle, and the *10 is the distance between the angles. Would the code be -30+loopindex*30?

  • Almost!

    It would be -60+loopindex*30.

    Explanation:

    Each fireball's angle gets set in the same loop as it was created.

    "loopindex" for the first loopindex is 1, for the second it's 2 and for the third it's 3.

    This means that for the first fireball created, the calculation would be -60+1*30 which is -30, exactly what we want. The second one would be -60+2*30 which would be 0. And so on.

    Now to make this simplier, you could exchange the "repeat" condition by a "for" condition, in this case "For 0 to 2".

    You would then change the "Set angle" action to exactly what you proposed, -30+loopindex*30, since the first loopindex would now be 0 and the last one 2.

    Choose whatever you prefer. :)

    (Remember: "Repeat" always starts at loopindex 1 while "For" makes you able to set where to start and where to end.)

  • I understand, which is amazing because i am math-challenged! Thanks, randomly!

  • If you need more reference for this subject, see the link to a topic:

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