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

I am a bit confused with the lastTime variable. I tried looking at this article:

https://coronalabs.com/blog/2013/06/18/guest-tutorial-delta-time-in-corona/

But I don’t think that is correct, or I just did not do it right. When I run this, the bullet does not move, and there are no error messages, just the target in the middle. This is the code:

require "ssk2.loadSSK" \_G.ssk.init() local function enterFrame(self) local vec = ssk.math2d.diff( self.tx, self.ty, self.x, self.y, true ) local len = ssk.math2d.length(vec) if( len \<= 0.05 ) then ignore("enterFrame", self) display.remove(self) return end vec = ssk.math2d.normalize(vec) local lastTime = 0 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) display.remove(self) return end vec = ssk.math2d.scale( vec, dm ) self.x = vec.x self.y = vec.y end local target = display.newCircle(centerX, centerY, 15) target:setFillColor(0.39, 0.16, 0.74) local bullet = ssk.display.newImageRect( target.group, 800, 800, "arrow.png", { size = 25, rotation = angle, myType = "bullet", fill = \_R\_ }) 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 bullet:addEventListener("enterFrame", bullet)

Also, what is .tx and .ty? Is it supposed to represent a certain value? Or is it supposed to be left alone?

.tx and .ty are the <x,y> position the bullet is moving to. i.e. the target <x,y>

This is the last time concept as a standalone piece of code:

local lastTime = system.getTimer() local function enterFrame( ) local curTime = system.getTimer() local dt = curTime - lastTime -- delta time == time since last frame lastTime = curTime print( dt, " milliseconds since last frame" ) end listen("enterFrame", enterFrame)&nbsp;

.

Thanks, but it still does not move:

require "ssk2.loadSSK" \_G.ssk.init() local lastTime = system.getTimer() local function enterFrame(self) local vec = ssk.math2d.diff( self.tx, self.ty, self.x, self.y, true ) local len = ssk.math2d.length(vec) if( len \<= 0.05 ) then ignore("enterFrame", self) display.remove(self) return end vec = ssk.math2d.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) display.remove(self) return end vec = ssk.math2d.scale( vec, dm ) self.x = vec.x self.y = vec.y end local target = display.newCircle(centerX, centerY, 15) target:setFillColor(0.39, 0.16, 0.74) local bullet = ssk.display.newImageRect( target.group, 800, 800, "arrow.png", { size = 25, rotation = angle, myType = "bullet", fill = \_R\_ }) 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 bullet:addEventListener("enterFrame", bullet)

Let me know if I am asking too much.

Yes, I feel at this point you are using my time and effort to make your game instead of to puzzle out issues with fundamentals.

I can’t afford to do that.  Sorry.

This will be my last answer on the question of turrets, projectiles, etc in this or any other thread you open.

I will only answer specific questions about something you are stuck on from now on.  

If you ask for full solutions that are not built into SSK2 the answer will be ‘work it out on your own’

Some Terrible Code (doesn’t match pseudo code from before and has no comments):

https://github.com/roaminggamer/RG_FreeStuff/raw/master/SSK2/forums_help/fire_inward_rotate.zip

A Video:

https://www.youtube.com/watch?v=acCyDCMCL-I&feature=youtu.be

I was probably kinda jerky in my last post, but I think we’re getting well beyond where my answers will help you with long term knowledge.  

Man,  on second reading my response was a little angry and/or mean sounding.

Let me clarify a little:

  1. The questions are interesting which is part of why I answered them.
  2. They use SSK2 which is cool.
  3. I’m pleased that you are digging into this and I love to see folks dig in.
  4. Also, I do want to help,              BUT…
  5. I think we’ve gotten beyond where my answers are helpful.
  • The code for the last example I gave is really not that great.
  1. The biggest problem for me is, we’re at a point where I know I’m not solving the problem you think you’re asking for help on and I don’t know how to clarify that misalignment nor do I know how to help you ask the right questions.
  2. I do feel a little like I’m doing free work too, and it isn’t even good work.  

So, carry on.  Don’t let me discourage you.  I will help when I think I can in a meaningful and useful way.

Cheers,

Ed

Thank you very much! 

I have two problems:

  1. The bullets are a bit flickery (they fade in and out rapidly), and this occurs when I try to change this line in the createTurretList function from this:

    angle = angle + 360/numTurrets 

To this: 

angle = angle + 300/numTurrets&nbsp;

I want to put it as 300, so the player has a gap to escape. 

  1. The arrows are jittery (the bullets vibrate in place). I am not sure why this happens. 

Here is the project: (minus SSK2)

That code I gave you for the last example has major issues.  I really wouldn’t solve the problem that way in my own games and I’m sure I made at least one mistake.  Not to mention, it is super inefficient, so it will be slow for 30+ projectiles (just guessing).

I wrote that sample so you could see it is entirely different from the prior linear velocity based turrets + projectiles.

Just to be clear, when I said this: 

This will be my last answer on the question of turrets, projectiles, etc in this or any other thread you open.

I meant it.   I won’t be able to help any more with this topic or thread.

Also, by this:

I will only answer specific questions about something you are stuck on from now on.  

I meant I’d help on future threads on new topics.

Good luck on your game.

Thank you for your time.

OK.  One more small response.

You have SSK2, and it contains this function:

https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/misc/#rotateabout

You might be able to make a copy of that code, modify it a bit, and get a ‘mover’ function for one projectile.  Then you can apply that to multiple.

It isn’t exactly what you want, but it is actually pretty close.

I have modified rotateAbout() and will release it with version 007 of SSK2 to allow for this effect.

https://www.youtube.com/watch?v=cB9KCTfx0do&feature=youtu.be

Code for red example (center bottom in video)

 local axis3 = newCircle( group, centerX, centerY + 150, { fill = \_R\_ }) local doBullets doBullets = function( axis, delay, count ) for i = 1, 10 do local tmp = newRect( group, axis3.x, axis3.y, { fill = \_R\_, size = 10 } ) local angle = i \* 36 ssk.misc.rotateAbout( tmp, axis3.x, axis3.y, { startA = angle, endA = angle + 360 + 36, time = 2000, radius = 125 } ) tmp.onComplete = function( self ) ignore("enterFrame", self) display.remove( self ) end transition.to( tmp, { \_\_radius = 10, time = 2000, onComplete = tmp }) end if( count ) then count = count - 1 if( count \<= 0 ) then return end timer.performWithDelay( delay, function() doBullets(axis, delay, count) end ) end end doBullets( axis3, 1000, 5 )

Keep your eyes open for the release.  I’m running late, but I’ll definitely push it by Monday evening.

Ok, I will keep my eyes peeled for the release. Where would I be able to find this update?

(kind of excited  :slight_smile: )

If you bought SSK2 here (the marketplace), then when the announcement is made (in forums by me) you simply need to download the new copy from your marketplace products page.

https://marketplace.coronalabs.com/profile

If you bought it elsewhere you will get an email from the store with a download link.

Also, always remember, when you’re not sure about what version of SSK2 you have versus what is the latest, go here and follow these directions:

https://roaminggamer.github.io/RGDocs/pages/SSK2/#are-you-using-the-latest-version

Current version (as I type this) is 2017.006; the next version (with this updated feature) will be 2017.007

Where would I find this announcement in the forums?

This is the announcement: 

https://forums.coronalabs.com/topic/67702-ssk2-updated-2017007-release/

Go here to get started using the updated version of ssk.misc.rotateAbout():

https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/misc/#rotateabout

I suggest you make a standalone test and learn to use the function first( see second example from docs).

Then, when you grok it, use it for your turret code.

Thank you! I got the update from Sellfy.