[Solved] Contra-Style Spread Gun


#1

Hello everybody.
In my game, there is an item that gives the player a chance to shoot a fan of 5 bullets at once, similarly to the Spread Gun from Contra. I tried to make something like this, but it just doesn’t seem to work. Does anybody know how to make a Contra-style Spread Gun in the most optimized way possible? Thanks in advance.


#2

hi, post your code to see what do you do wrong
It occurs to me that you could do a repeat loop and shot 5 bullets, is that what you want?


#3

Here it is (look under the HASSPREADBULLETS tab).


So far, that is the best I can do, just making all 5 bullets shoot in a random fan. Is it possible to make each individual bullet travel in it’s own specific direction, even if the “repeat” event is used? Or will this require more code? Or should I just stick with what I have?
(Note: I have the bullet spawning the spread bullets, which are called “ExtraBullets”. Should this be changed? If so, then how?)


#4

hi
What i understand from your code is that yo do 5 times
create extrabullet and for each bullet in the game add a permanent force with random angle to the created extrabullet.
Is that what you want to do?!
Maybe you could explain the behaviour to see if the code is correct.


#5

Technically, no. I would like each individual bullet to fly in a specific direction, such as bullet 1 to fly at 170 degrees, bullet 2 to fly at 175 degrees, and etc.


#6

Maybe a good way achieve that is using custom points in sprite itself like in this example


And try from there to specify the angle of the individual bullets


#7

i think it is possible, could you share your project(remove anything not necessary if you want) and i’ll try to fix it.
It is hard to tell when you can’t see what you are doing :wink:


#8

Hello, sorry for the late reply. I changed the point where the bullets are created to the character instead of the bullets. Here is the new code (Under HASSPREADBULLETS again):


It works good right now. So now how do I have each bullet travel in it’s own individual direction? Thanks in advance.


#9

So this is my way for sure maybe a more good way exist but this is how i would do it with my knowledge so far.


Make sure the origin and pivot of the bullet is also on the center of the sprite

Edit: I have the point in the player sprite too if you want to have different guns with different sizes I think for simplicity is a good option to keep the points in player sprite instead to the gun itself and play just with the position of the points

And this is an update with more clean actions and fire rate


#10

It worked! Thanks mate! :smiley: