Get An Enemy To Fire Bullets at 8 Angles?

Get help using Construct 2

Post » Mon Jan 27, 2014 7:51 am

Hi,

I have a script set up so that, when Space is pressed, an enemy called a Boombox in my game will be destroyed and release bullets in 8 different directions, at 45 degree angles (e.g. 0, 45, 90 and so on). However, the enemy just fires lots of bullets down rather than firing them in different directions. I know that there are lots being fired because of the debugger, but they are all heading in the same direction.

Here is my code:

(If the picture doesn't work, here it is)

Can anybody help me?

Thank you!
B
8
S
2
G
2
Posts: 49
Reputation: 1,894

Post » Mon Jan 27, 2014 8:21 am

Using sub-events, you make sure only the bullet in the event above is referenced.

I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Jan 27, 2014 8:55 am

and another function to do basically the same thing

Function to fire (random ?) number of bullets around player
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Mon Jan 27, 2014 12:13 pm

@OrangeFlash81,

Just so you understand why your method didn't work: when you use a spawn, the spawning object's attributes are inherited by the created object. This includes the object's angle (so, on your example, I'm guessing that the Boombox was set at 90 degrees for all of the bullets to travel downwards). This spawn action overrides any immediately subsequent attempts to change these inherited attributes. Son any attempt to change an angle after a spawn will never work.

A crazy alternative method would be to create 8 invisible gun objects and pin them to the player, with each one set at 45 deg to the last. Then, when you shoot, you just have one line commanding "gun: spawn bullet" - the event system will select all guns and spawn all of the bullets for you.

Hope this helps!
A big fan of JavaScript.
B
76
S
20
G
76
Posts: 2,296
Reputation: 47,576

Post » Mon Jan 27, 2014 12:36 pm

[QUOTE=Colludium]
This spawn action overrides any immediately subsequent attempts to change these inherited attributes. Son any attempt to change an angle after a spawn will never work.
[/QUOTE]

Are you sure this is right ? RamPackWobble2014-01-27 12:37:49
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Mon Jan 27, 2014 1:03 pm

@RamPackWobble,

Err - no! My mistake - it appears that I need to go back to the manual (again!!). I have also encountered @OrangeFlash81 's problem before and just assumed that this was the case (a system create object never causes the non-setting of attributes as shown in the OP).

A big fan of JavaScript.
B
76
S
20
G
76
Posts: 2,296
Reputation: 47,576

Post » Mon Jan 27, 2014 1:04 pm

Try this instead:

+on "BoomboxExplodeNow"
+For "" from 0 to 7

-Create [StandardEnemyBullet]
-Set angle of motion to loopindex*45 degrees

MadFactory2014-01-27 13:06:40
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770

Post » Mon Jan 27, 2014 1:13 pm

@Colludium @OrangeFlash81 the reason it doesn't work in the first post is because every item spawned is added to the current object selection. So every "Set bullet angle" is applied to all the bullets in the current selection, and this is why the same angle is on every bullet at the end.
LittleStain had it right, it should work this way, even if it's not that beautiful. MadFactory solution is nicer and will also work (as the new bullet is created inside the loop, thus not added to the current object selection on next loop index).
B
17
S
8
G
4
Posts: 473
Reputation: 6,221

Post » Mon Jan 27, 2014 1:14 pm

As we have not seen the capx I am going to make an assumption - and that assumption is that the bullets (when spawned) have zero speed. A bullet with zero speed can not have any angle of motion except 0. A bullet travelling at an angle of 45 degrees that is stopped (speed) and then restarted will travel at 0 degrees.

(example of bullet "changing direction" because of zero speed)

So if you are spawning your bullets with zero speed and then setting the angle of motion and then altering the speed then the bullets will travel at 0 degrees!

But like I said - all assumption (and yes I am waiting fot the "Silence of the lambs" quote )
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Mon Jan 27, 2014 1:18 pm

Did anyone even look at my original capx ?




and while I am at it (spitting out my dummy and stamping around !)



works !



None working function that works

Time for a coffee and my medications I think !RamPackWobble2014-01-27 13:34:43
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 29 guests