# How do I make diagonal shooting

Get help using Construct 2

### » Wed Jan 14, 2015 7:05 pm

Hello guys,

I managed to create events for diagonal shooting, but there is an overlapping of buttons when we, for instance, shoot Up and Up+Right. Look at my code (event 10 and 15 )

And this is what we are getting as a result when we shoot up+right (here you see that bullet UP direction is triggered as well)

So, how can I exclude UP shooting from the event UP+Right direction (event 10)?

Or maybe there is a more simple method of diagonal shooting..
B
8
S
2
Posts: 48
Reputation: 646

### » Wed Jan 14, 2015 7:11 pm

Add right arrow is down on your 15th line and invert it. (right click on it and left click "invert", a red "X" should appear before it)
B
18
S
4
Posts: 87
Reputation: 1,199

### » Wed Jan 14, 2015 7:17 pm

You should nest those conditions...

Code: Select all
`On D pressed  >>  (player) Spawn bullet   if up arrow is down       if left arrow is down  >> (bullet) Set angle to -135 degrees       else if right arrow is down  >> (bullet) Set angle to -45 degrees       else  >> (bullet) Set angle to -90 degrees   else if down arrow is down       if left arrow is down  >> (bullet) Set angle to 135 degrees       else if right arrow is down  >> (bullet) Set angle to 45 degrees       else  >> (bullet) Set angle to 90 degrees`
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
22
S
6
G
3
Posts: 717
Reputation: 3,996

### » Wed Jan 14, 2015 8:44 pm

brunopalermo wrote:You should nest those conditions...

Code: Select all
`On D pressed  >>  (player) Spawn bullet   if up arrow is down       if left arrow is down  >> (bullet) Set angle to -135 degrees       else if right arrow is down  >> (bullet) Set angle to -45 degrees       else  >> (bullet) Set angle to -90 degrees   else if down arrow is down       if left arrow is down  >> (bullet) Set angle to 135 degrees       else if right arrow is down  >> (bullet) Set angle to 45 degrees       else  >> (bullet) Set angle to 90 degrees`

This is a great logic, though the system does not allow to put "else" after the first condition.

It perfectly worked for 6 directions, except of right and left.

By the way, how can we add left and right direction to this code? We now have an overlap with these buttons if we separately assign to them left and right directions.
B
8
S
2
Posts: 48
Reputation: 646

### » Wed Jan 14, 2015 9:06 pm

Bundle them all together, no overlap ever possible.

shootdiag.PNG

Last "else" statement is there if you want to add a default direction.
You do not have the required permissions to view the files attached to this post.
B
80
S
33
G
27
Posts: 1,027
Reputation: 21,114

### » Wed Jan 14, 2015 10:06 pm

Magistross wrote:Bundle them all together, no overlap ever possible.

shootdiag.PNG

Last "else" statement is there if you want to add a default direction.

oh , thanks
almost done

Now, whether he is turned left or right , he is always shooting right. How can I set it to shoot left when is looking to the left?
B
8
S
2
Posts: 48
Reputation: 646

### » Wed Jan 14, 2015 10:18 pm

That's what the last "else" is there for. You just need to complete it with the condition of your choice. On the top of my head, I see your sprite is mirrored, so you might consider setting it to :
Code: Select all
`ElsePlayer is mirrored         -> Set Bullet angle to 180`
B
80
S
33
G
27
Posts: 1,027
Reputation: 21,114

perfect
B
8
S
2
Posts: 48
Reputation: 646

### » Thu Jan 15, 2015 11:58 am

Yes, it does allow the Else statement where I put it... Also, no need to mirror anything, just set the bullet to Set angle according to the angle of movement...

diagonal-bullet-example.capx

I wouldn't check for the keys, by the way. Instead, you could check the facing by having such a variable, thus this would also work even if the player is not moving...
You do not have the required permissions to view the files attached to this post.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
22
S
6
G
3
Posts: 717
Reputation: 3,996

### » Thu Jan 15, 2015 1:42 pm

brunopalermo wrote:Yes, it does allow the Else statement where I put it... Also, no need to mirror anything, just set the bullet to Set angle according to the angle of movement...

diagonal-bullet-example.capx

I wouldn't check for the keys, by the way. Instead, you could check the facing by having such a variable, thus this would also work even if the player is not moving...

it would be a nice addition, to post the version # of construct being used for the capx.

gonna have to get 194.2 now...
B
9
S
2
Posts: 80
Reputation: 864