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

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.

I can’t help you with this.  This is the kind of thing I would put in a paid pack.

One major problem, is that it is an entirely different concept and mechanic from the code I wrote in the prior modules.

Second, I guarantee when you look at the effect and I look at it, we are seeing different things.  So expressing what I see such that you can use it to achieve the effect you are envisioning would be a lot of work for me.

I will tell you this:

  • That attack does NOT use physics movement (no linear velocity or forces).
    • This might actually lend itself to a non-physics based collision detection scheme, but you can hack it together and make it work with physics collision detection.
  • The ‘bullets’ are moved manually via a calculation.
    • Some might think you could hack this by putting the bodies in a group and rotating the group.  That won’t work.
  • You have to calculate the path and rotation about a point for every ‘bullet’ individually, on every frame.
  • There is a very inefficient way to do this, and there is at least one much more efficient method to achieve this.

-Ed

I’ll give you pseudocode for creating and moving ONE bullet, you can expand that to multiple bullets.

enterFrame listener

enter frame begin local vec = diffVec( self.tx, self.ty, self.x, self.y, true ) local len = lenVec(len) if( len \<= 0.05 ) then ignore("enterFrame", self) delete self return end vec = normalize(vec) local curTime = system.getTimer() local dt = curTime - lastTime self.lastTime = curTime local dr = self.rotRate \* dt / 1000 local dm = self.moveRate \* dt / 1000 if( dm \> 0.05 ) then ignore("enterFrame", self) delete self return end vec = scaleVec( vec, dm ) self.x = vec.x self.y = vec.y end enter frame

When creating ‘bullet’

local bullet = newBullet( ... ) bullet.tx = target.x bullet.ty = target.y bullet.rotRate = 90 -- rotate about target at 90-degrees per second bullet.moveRate = 200 -- move at 200 pixels per second bullet.enterFrame = enterFrame listen("enterFrame", bullet)