0 Favourites

How do I make diagonal shooting

  • 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..

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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)

  • You should nest those conditions...

    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[/code:2t8180v2]
  • You should nest those conditions...

    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[/code:17dpfl5w]
    

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

    I made the following split

    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.

  • Bundle them all together, no overlap ever possible.

    [attachment=0:q75k3s1e][/attachment:q75k3s1e]

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

  • Bundle them all together, no overlap ever possible.

    [attachment=0:2qfz8hol][/attachment:2qfz8hol]

    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?

  • 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 :

    Else
    Player is mirrored 
            -> Set Bullet angle to 180[/code:3ble85qo]
  • perfect

  • 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...

    [attachment=0:h30ocdcn][/attachment:h30ocdcn]

    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...

  • 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...

    [attachment=0:1pwbbm5q][/attachment:1pwbbm5q]

    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...

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)