How to coding diagonal shoot like Metal Slug

Godot Version

Godot 4.2.1`

Question

Hello, I am a beginner in coding and I would like to reproduce the diagonal shooting system that can be seen in the Metal Slug, that is without touch for diagonals and with only a few projectiles that go in this direction.

To be more precise, I would like to reproduce the system of the game “Gaurodan” of LOCOMALITO at the level of control of the shots.

I’m not sure it’s very clear, but thank you in advance for the people who can help me

Sorry for my bad English (I’m a frog eater.)

Do you mean that when the player presses up and left for movement, say, the weapon fires diagonally up and to the left? Is that what you are describing?

(Oh, and also to have only a limited number of shots that can go diagonally? Is that right?)

Not quite, there is no key to shoot in the direction “down” for example.

In the game there are 2 shooting keys, 1 for side direction and 1 for shooting diagonally.

However, if during our diagonal shooting, we change direction, there are some small frames during which he will pull the directions between the 2 sides (in Gaurodan it is down, and in Metal Slug it is up.)

And this is what I would like to reproduce.

First I would give a name to the system of shooting in both diagonal directions for a short period, perhaps somehting like “staggered_diagonal_fire”.

Then I would set bool flags for:
is_firing_diagonal_staggered’ to indicate if this is in action or not.
is_direction_change_recent’, to see if we have recently changed directions.
is_firing_staggered_in_movement_direction’, so we can flip this for left, then right, etc.

Then you would set these appropriately:

When the player changes direction:
is_direction_change_recent = true

When the player starts firing:

if is_direction_change_recent:
     is_firing_diagonal_staggered = true

In your weapon system if diagonal firing flip direction each time you fire:

if is_firing_diagonal_staggered:
    is_firing_staggered_in_movement_direction = not is_firing_staggered_in_movement_direction

Then when you fire your diagonal weapon, its direction is decided by is_firing_staggered_in_movement_direction and your current movement direction left or right. This will flip every time your weapon is fired until is_firing_diagonal_staggered changes to false.

You can then either, use a timer or a delta counter to set is_firing_diagonal_staggered back to false when your max time is exceeded, or you can count each diagonal fire when it is staggered and change it to false when you have fired, say, four diagonal shots.

You would then set a timer for the is_direction_change_recent. Whenever your player changes direction you reset this timer. When your is_firing_diagonal_staggered is due to reset, you re-check the is_direction_change_recent, and if it is again (as the player may have again changed direction) you can reset the staggered_diagonal firing timer or counter. So your player keeps firing in both directions if they are swapping directions rapidly.

So you have a flag and timer for ‘if direction change is recent’. Plus a flag and timer (or counter) for your ‘is alternating diagonal fire’. A direction change then allows for the alternating diagonal fire to be possible. When its counter or timer runs out, check if direction change is still recent and start again if it is.

Anyway, that’s sort-of how I would approach it. Hope that helps and was not too basic an answer for you.

Thanks! I’ll try that.

1 Like