Have multiple bullets fire inward in a circle formation (SSK2)

I had received great help on having a turret that fires bullets in all directions, but I was wondering how could I have many bullets that fire inward. What I would want to do is create a circle that shows where the bullets will form, then the circle disappears, the bullets appear, and they fire inward at one target. How could this be accomplished?

I suspect that you can use the previous example Roaming Gamer provided and  change it’s destination. I recall seeing the bullets curving, I expect they are ‘aiming’ at something, so you may be able to leverage that code to make it more circular. (Possible within easing)

Worth a look IMHO.

Yes, but my problem with that would be that I don’t want any turrets to appear. Also, I am not at all familiar with the mathematics of Corona SDK and SSK2. For instance, if there are 4 bullets they will come in at 4 directions with equal distance form each other, 5 bullets, 5 directions with equal distance, 6, 7, 8 and so on.

Notes

  1. I suggest you take some time out to understand and learn about 2D vector math.  This topic has been at the core of all your turret questions.  Once you know this topic you will be much better prepared to self solve.  This is a crucial topic for action games and other genres too.

Questions you should answer:

  1. How many projectiles will be fired?
  2. Will they be evenly distributed about the circumference of the circle. i.e If there are 4, do you want one fired from every 90-degrees about the circle?
  3. What is the radius of the circle?

Then, with SSK2 you can do this to make the list of turrets:

-- may contain typos local function createTurretList( target, numTurrets, radius ) local turrets = {} local angle = 0 for i = 1, numTurrets do local vec = ssk.math2d.angle2Vector( angle, true ) vec = ssk.math2d.scale( vec, radius ) vec = ssk.math2d.add( target, vec ) turrets[#turrets+1] = vec angle = angle + 360/numTurrets end return turrets end

Now,do this (using the new turretM.lua module that takes a list of turrets):

local target = display.newCircle( centerX, centerY, 20 ) local turrets = createTurretList( target, 9, 200 ) turretM.fire( turrets, target )

Fixed typos.

Ok, so I would create the function from the first block in turretM.lua, (which is now called attack.lua, if I reference it that way), then write the code in the second block in main.lua. Is this correct?

Thank you so much, it works great. I have one question, where can I learn more about 2d vector math?

I don’t really know, I would google it.  I learned this stuff in formal classes (over 20 years ago), but I don’t think you’ll be doing it that way. :slight_smile:

This is part of the complaint/problem I have.  I wish I had a set of ‘go do this first’ items I could just give every developer, but the level and experience of developers varies so much it is hard to put such a list together.  Not to mention, keeping the list up-to-date is hard too.

Try googling “learn 2d math games”  or “learn 2d vector math games”

I found these possibilities:

Some of the above links may lead to ‘complicated’ seeming math with dot products, cross products, cos(), sin(), etc.  Just skip those and try another source till you find ones that talk about simple topics like adding, subtracting, etc.

Please remember, ssk2.math2d takes all the heavy lifting out of vector math.  You simple have to understand the high-level concepts of 2d math.  So focus on tutorials and discussions that cover the high-level stuff, like (I believe) that video link above.

-Ed

The nature of code is a great source for 2d and other game related concepts.

http://natureofcode.com/book/chapter-1-vectors/

Thanks for the suggestions, may I ask you one last thing, is it possible to have both visible turrets shooting and the inward bullets moving at the same time. I tried doing this, but only one of them works because they have the same variable names.

I’m afraid I don’t understand the question.  

I mean that I had 5 visible turrets created by this table:

for i = 1, 5 do local turret = ssk.display.newImageRect( content, left + (i-1) \* ox + ox/2, bottom - 75, "rg256.png", { size = 35, fill = \_W\_ } ) turrets[#turrets+1] = turret end

But I can’t make them fire, because the of the other function which is the bullets firing inward. The variable names are the same. For example, I can’t have both the 5 turrets and the inward circle of bullets happening at the same time, it is one or the other, how can I make so both are capable of firing at the same time? 

Sure you can…

** FIXED TYPO**

local target = display.newCircle( centerX, centerY, 20 ) local turrets\_fixed = {} for i = 1, 5 do local turret = ssk.display.newImageRect( content, left + (i-1) \* ox + ox/2, bottom - 75, "rg256.png", { size = 35, fill = \_W\_ } ) turrets\_fixed[#turrets\_fixed+1] = turret end local turrets\_circle = createTurretList( target, 9, 200 ) turretM.fire( turrets\_fixed, target ) turretM.fire( turrets\_circle, target )

The names used for variables IN the module have nothing to do with how you call it or what variables you use in the code that calls the module method.

Thanks! Also, how could I make the bullets spin around in their circle formation. As in, they move around on the circumference of the circle in unison.

For example: 

https://www.youtube.com/watch?v=Eqypnw6gQNg

In this battle, notice how there is a spinning attack where bullets come inward and some of them spin around.

Sorry, for all these questions.

  1. Thanks for the video, but if you want to point out a specific part, please give the time in the video where it happens. 8 minutes may not seem like a lot, but i’m not patient enough to hunt it down.

  2. The projectile motion effects I’m seeing are completely different kind of projectile/bullet concept from the one I’ve helped you put together.  So, I can’t really help with this.

I will make a note on my general list in case I have time to do a kit of turrets and projectiles some day in the future.

You will see what I am talking about at 3:51 to 4:00, and at 4:21 to 4:28. I am not interested in the other projectile motion effects at this point, just that one in particular.

Yeah, that is done differently from the code I’ve written.  I can’t help with this today.

Ok, no problem.

What would I need to do in order to accomplish this “rotating” attack?

Also, I would like for you to just give me instructions in which math2d functions to use, instead of giving me the code directly, I feel kind of bad that you have been giving me this code for free.  

Also, I hope you won’t mind that I ask you a few questions about some of the math2d function in SSK2.