How do I make a multi-bullet?

Just started using Construct 2? Post your questions here

Post » Fri Nov 04, 2016 10:31 pm

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.

Image
B
7
Posts: 63
Reputation: 403

Post » Sat Nov 05, 2016 12:15 am

At the point where you want to spawn the three bullets, add this:

Code: Select all
Repeat 3 times [condition]
       -> Create object "fireball" [action]
       -> "fireball": set angle to: -20+loopindex*10


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: Select all
"fireball": set angle to: ([highest angle you want] minus [angular difference between fireballs]) +loopindex * [angular difference between fireballs]


If you need more help, just send me your .capx or post the context of those fireballs, like angles and stuff.
Last edited by randomly on Sat Nov 05, 2016 2:01 am, edited 1 time in total.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Sat Nov 05, 2016 12:32 am

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 [list]? 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.
B
7
Posts: 63
Reputation: 403

Post » Sat Nov 05, 2016 2:09 am

Whoopsiewhoo, that [list] and [*] was a formatting fault by me. Keep forgetting that BBCode doesn't work in code..
Anyways, set it up like this:
Image

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:
Image
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Sat Nov 05, 2016 4:10 pm

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?
B
7
Posts: 63
Reputation: 403

Post » Sat Nov 05, 2016 5:27 pm

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.)
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Sat Nov 05, 2016 5:31 pm

I understand, which is amazing because i am math-challenged! Thanks, randomly!
B
7
Posts: 63
Reputation: 403

Post » Sat Nov 05, 2016 8:06 pm

If you need more reference for this subject, see the link to a topic:
viewtopic.php?f=147&t=169329&p=1019230&hilit=+bullet#p1019230
ImageImage
B
105
S
46
G
23
Posts: 778
Reputation: 22,226


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests