Random bullet direction.

For questions about using Classic.

Post » Sun Mar 21, 2010 8:59 am

Hello there. This might me a little bit of a newbie question but I figured I'll ask for help.

So here I am trying to create a basic top down shooter. However I'm having trouble getting the enemy to shoot In a random direction. I want them to shoot In front of them - like this ugly paint drawing can illustrate.


However I can only get them to shoot straight.

An "always" and " "set angle" event obliviously don't work.

Then I tried to set it to the "X millisecond, spawn a bullet" event but that only made a few fly in different directions.

I'm at your mercy. Please help me!
B
1
G
3
Posts: 5
Reputation: 835

Post » Sun Mar 21, 2010 9:16 am

Assuming that your bullets have Bullet behaviour, you can do the following:

+Every 100 ms
> BigBadMeanGuy: Spawn Bullet
> Bullet: set angle to BigBadMeanGuy.Angle - 45 + random(90)

They will fire randomly within the 90 degree cone in front of them.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sun Mar 21, 2010 9:29 am

That's what I also thought. But they just shoot straight for some reason.



That's what the Event looks like.

Edit:

Thanks to the "X.Angle - 45 + random(90)" command the they shoot in the correct angle. But it's only working on some enemies for some reason.
B
1
G
3
Posts: 5
Reputation: 835

Post » Sun Mar 21, 2010 9:38 am

Hm, do you have any other events or behaviors affecting the bullets?
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sun Mar 21, 2010 9:45 am



That's the only thing I can think of.


(place holder graphics)

This is what it looks like in game.
B
1
G
3
Posts: 5
Reputation: 835

Post » Sun Mar 21, 2010 9:48 am

Well, I can't tell what's making them fly straight without looking at the .cap.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sun Mar 21, 2010 9:58 am

B
1
G
3
Posts: 5
Reputation: 835

Post » Sun Mar 21, 2010 10:12 am

Add the following condition to the Every 800 ms event:

For each enemy_1
(you'll find it in System)

This will ensure that each enemy is evaluated instead of all at once, thus in turn each bullet will shoot off into its own direction.

Also, get rid of the enemy_bullet1_collition. Just check for collisions between bullets and player. (The collition sprites weren't moving at all, by the way. They stayed where they were spawned.)

You might want to move the player_bullet action to the spawning event. It is pointless to change its angle to -90 every tick, once it is already facing that angle.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sun Mar 21, 2010 10:16 am

It worked!
I could not thank you enough!
You sure are a lifesaver!
B
1
G
3
Posts: 5
Reputation: 835

Post » Sun Mar 21, 2010 10:19 am

Imagine that conditions are filters; all objects that pass through the filter are treated as one when you apply the action to them. The "For Each Object" condition instead executes the action for each individual object that passes the filter.

I hope that helps clear it up :)
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests