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!