8 direction shooting problem [SOLVED]

0 favourites
  • 3 posts
From the Asset Store
Rotate & Animation for 16 Direction & Mouse Direction
  • Hey guys!

    So, in this game I'm making, the character will be able to shoot in 8 directions (like Samus does in Super Metroid). Only exception will be that, while on the ground, you won't be able to shoot down (only while jumping). So... you have 7 directions while on the floor and 8 directions while on the air.

    Anyway, the system is pretty much done, the problem I'm having looks simple but It's really frustrating me since I've ran out of ideas of what might be causing it. The system works like this:

    First, the aiming. I check what buttons are being pressed in order to know what direction the character is aiming towards. It goes like this:

    Baixo stands for Down and Cima equals Up. Code is in portuguese because I'm brazillian.

    So, as you can see, I call a function with the direction parameter. All the function does is put the parameter value in a variable.

    Then I run a lot of checks (too much to show here) that checks the value of this variable and sets a value to the bullets that are shot. For example, DiagonalCima (or DiagonalUp) will make bullets go in angle 315 if not mirrored and 225 if mirrored.

    These "mira" values (DiagonalCima, Normal, Cima, etc) are set into the character's animation so he swaps to the right one:

    That Else reads Set animation to Box.estado (the state the character is in, like Walk, Jump, Idle, etc) & the direction. So if you're aiming up while Idle, the animation that plays is Idle_Cima

    So yeah I added animations for every state and for every possible direction the character can aim, with imagepoints on where the bullet is shot on each specific direction

    The animation swapping is working fine. The problem is in the shooting...

    When you press X to shoot, a function is called

    The function turns true a boolean, that will then do what it has to do

    The bullet is created succesfully, the bullet direction is set succesfully. The problem is that, they are not always created in the right image point. Specifically, when you're shooting diagonally up, if you suddenly stop moving horizontally sometimes the next bullet is sent up but on the diagonal imagepoint. You might be asking yourself why I created a function just to set a boolean true THEN for the shooting to happen, all this was an attempt to stop this problem. What is happening is that if I change shooting direction too quickly the animations don't swap quick enough and a bullet that goes up sometimes is created on the imagepoint of the diagonal up bullet.

    I've messed with the events orders A LOT since I thought this had to be the cause. This is what it is right now:

    Here is a demo for you to see the problem:

    https://marcosfuchter.itch.io/shooting8dir?secret=YZPRDtwbUOVA76RUbjvfuWGHbg

    Try this: keep pressing X to shoot, then start messing with the Up and left keys (shooting diagonally up, and up). You'll see that a lot of times the bullet goes in the right direction, but is created on the wrong imagepoint!

    Really sorry for the big post but, if you've read it all up to this point I hope you can help me. It was a really specific issue so I had to explain it all. Thank you very much!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey marcosfl!

    Not sure this is what you need, but...

    https://www.dropbox.com/s/1xwrduwu0e18t ... .capx?dl=0

    I hope this helps. Cheers!

  • Hey marcosfl!

    Not sure this is what you need, but...

    https://www.dropbox.com/s/1xwrduwu0e18t ... .capx?dl=0

    I hope this helps. Cheers!

    Before you replied, I dug deep in here and found what the problem was. Actually it wasn't on the system itself, but on the animations! If you're aiming diagonally, the character is moving, and if you suddenly stop pressing left or right you're aiming up, but the character still moves for a while due to deceleration! The problem was that I didn't have a "Walk_Up" animation, so it used the imagepoint of the previous animation (Walk_DiagonalUp) to shoot the bullet!

    Thank you for the capx though! I'll study it and maybe do some tweaks on my programming <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

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