-SOLVED-Random bullet from turret

Get help using Construct 2

Post » Thu Apr 04, 2013 8:07 pm

Hello everyone.

I have a peculiar situation at hand. I crated a sprite, gave it turret behaviour, added two different bullet sprites (red and green) and want the turret to shoot a random bullet each time. (there is also an irrelevant trick where turret shoots in irregular intervals as you will see.) Below is what I came up with:

global variable what to shoot = 1

cond:
on turret shoot
whattoshoot = 1
act:
create object redbullet on layer 1 at enemybird image point 1 x and y
play sound
set redbullet angle to enemybird.angle
set turret rate of fire to 4-random(1,2.5)
set whattoshoot to round(random(0.9,2.1)

cond:
on turret shoot
whattoshoot = 2
act:
create object greenbullet on layer 1 at enemybird image point 1 x and y
play sound
set greenbullet angle to enemybird.angle
set turret rate of fire to 4-random(1,2.5)
set whattoshoot to round(random(0.9,2.1)

supposedly the enemybird will either shoot a green bullet or a red bullet, then random will create between 0.9 and 2.1 and round will change it to either 1 or 2. so next time relevant bullet will shoot. And it works! But sometimes, it shoots both bullets together. There is no other event outside of these related to turret behaviour or bullets. Does anyone have any idea what I could be doing wrong?Windwalker2013-04-04 20:55:09
B
16
S
4
G
1
Posts: 332
Reputation: 3,016

Post » Thu Apr 04, 2013 8:45 pm

Wait, why are you declaring whattoshoot so far down the list of actions. Surely it should be set first, as the shooting action takes place?

I.e.:

On turret shoot -> set whattoshoot random etc.
sub-events:
whattoshoot = 1...
whattoshoot = 2...
B
56
S
15
G
10
Posts: 910
Reputation: 11,942

Post » Thu Apr 04, 2013 8:51 pm

Geometrix, I moved it up but it didn't work either. Though I really don't know why I couldn't think of doing it the sub-evet way. I started only couple days ago, so fresh... Thanks for the help, I will try it that way.
B
16
S
4
G
1
Posts: 332
Reputation: 3,016

Post » Thu Apr 04, 2013 8:54 pm

It worked! Thanks Geo!
B
16
S
4
G
1
Posts: 332
Reputation: 3,016


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests