How to make multiple projectiles go in different directions

I am trying to make projectiles move out of a circle at the center of the screen. There are 18 projectiles and I want them all to move outward from each other in 18 directions with equal space between each other, how can I achieve this? 

This is my code so far:

local orb = display.newCircle(display.contentCenterX, display.contentCenterY, 60) orb:setFillColor(0.6, 0.7, 0.9) local function spawnProj() for a = 1, 18 do count = count + 1 local bullet = display.newRect(display.contentCenterX, display.contentCenterY, 10, 80) physics.addBody(bullet, "dynamic", {density = 5, isSensor = true}) bullet.gravityScale = 0 bullet.rotation = count \* 20 end end spawnProj()

This is pretty easy to do with SSK2.  

This video shows a simple example in only 70 lines of code (projectile code fireTurret() was only  about 15 lines of code).

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

(Download code [minus SSK2] here: http://github.com/roaminggamer/RG_FreeStuff/commits/master/SSK2/forums_help/projectiles.zip )

require "ssk2.loadSSK" \_G.ssk.init( {} ) require "physics" physics.start( ) physics.setGravity(0,0) local lifetime = 5000 local projectileCount = 3 local spread = 7 local bulletSpeed = 300 local turret local fireTurret local lastTarget local background = display.newGroup() local content = display.newGroup() local function onCollision( self, event ) display.remove(self) return false end local function onCollision2( self, event ) if( event.other.myType == "bullet" ) then return false end display.remove(self) end local function onTouch( self, event ) if( event.phase ~= "began" ) then return end lastTarget = ssk.display.newImageRect( content, event.x, event.y, "corona256.png", { size = 40, collision = onCollision }, { radius = 20 } ) fireTurret() end ssk.display.newRect( background, centerX, centerY, { w = fullw, h = fullh, fill = \_G\_, alpha = 0.2, touch = onTouch } ) turret = ssk.display.newImageRect( content, centerX, bottom - 75, "rg256.png", { size = 100 } ) ssk.misc.addSmartDrag( turret ) fireTurret = function() local vec = ssk.math2d.diff( turret, lastTarget ) local angle0 = ssk.math2d.vector2Angle(vec) local angle = angle0 - spread \* (projectileCount-1)/2 for i = 1, projectileCount do local vec2 = ssk.math2d.angle2Vector( angle, true ) vec2 = ssk.math2d.normalize(vec2) vec2 = ssk.math2d.scale( vec2, bulletSpeed ) local bullet = ssk.display.newImageRect( content, turret.x, turret.y, "arrow.png", { size = 20, rotation = angle, collision = onCollision2, myType = "bullet", fill = randomColor() }, { isSensor = true, radius = 10} ) bullet:toBack() bullet:setLinearVelocity( vec2.x, vec2.y ) bullet.timer = display.remove timer.performWithDelay( lifetime, bullet ) angle = angle + spread end end

Thanks, this is an amazing project! But could you help me with my problem, is there an equation I should construct in order to make them go in different directions?

I am trying to achieve this with transition.to() and I am not going to try this yet. However, I am very interested in it. I would just like to know how to do this with no plugins or modules.

Also, I am having trouble making the arrows face outward. This is my code so far:

local function spawnProj() for a = 1, 4 do count = count + 1 local bullet = display.newImageRect("arrow.png", 64, 64) bullet.x = display.contentCenterX bullet.y = display.contentCenterY bullet:setFillColor(math.random(), math.random(), math.random()) physics.addBody(bullet, "dynamic", {isSensor = true}) bullet.gravityScale = 0 end end spawnProj()

EDIT: I bought SSK2 Lite and I will be trying to solve this problem now.

This is pretty easy to do with SSK2.  

This video shows a simple example in only 70 lines of code (projectile code fireTurret() was only  about 15 lines of code).

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

(Download code [minus SSK2] here: http://github.com/roaminggamer/RG_FreeStuff/commits/master/SSK2/forums_help/projectiles.zip )

require "ssk2.loadSSK" \_G.ssk.init( {} ) require "physics" physics.start( ) physics.setGravity(0,0) local lifetime = 5000 local projectileCount = 3 local spread = 7 local bulletSpeed = 300 local turret local fireTurret local lastTarget local background = display.newGroup() local content = display.newGroup() local function onCollision( self, event ) display.remove(self) return false end local function onCollision2( self, event ) if( event.other.myType == "bullet" ) then return false end display.remove(self) end local function onTouch( self, event ) if( event.phase ~= "began" ) then return end lastTarget = ssk.display.newImageRect( content, event.x, event.y, "corona256.png", { size = 40, collision = onCollision }, { radius = 20 } ) fireTurret() end ssk.display.newRect( background, centerX, centerY, { w = fullw, h = fullh, fill = \_G\_, alpha = 0.2, touch = onTouch } ) turret = ssk.display.newImageRect( content, centerX, bottom - 75, "rg256.png", { size = 100 } ) ssk.misc.addSmartDrag( turret ) fireTurret = function() local vec = ssk.math2d.diff( turret, lastTarget ) local angle0 = ssk.math2d.vector2Angle(vec) local angle = angle0 - spread \* (projectileCount-1)/2 for i = 1, projectileCount do local vec2 = ssk.math2d.angle2Vector( angle, true ) vec2 = ssk.math2d.normalize(vec2) vec2 = ssk.math2d.scale( vec2, bulletSpeed ) local bullet = ssk.display.newImageRect( content, turret.x, turret.y, "arrow.png", { size = 20, rotation = angle, collision = onCollision2, myType = "bullet", fill = randomColor() }, { isSensor = true, radius = 10} ) bullet:toBack() bullet:setLinearVelocity( vec2.x, vec2.y ) bullet.timer = display.remove timer.performWithDelay( lifetime, bullet ) angle = angle + spread end end

Thanks, this is an amazing project! But could you help me with my problem, is there an equation I should construct in order to make them go in different directions?

I am trying to achieve this with transition.to() and I am not going to try this yet. However, I am very interested in it. I would just like to know how to do this with no plugins or modules.

Also, I am having trouble making the arrows face outward. This is my code so far:

local function spawnProj() for a = 1, 4 do count = count + 1 local bullet = display.newImageRect("arrow.png", 64, 64) bullet.x = display.contentCenterX bullet.y = display.contentCenterY bullet:setFillColor(math.random(), math.random(), math.random()) physics.addBody(bullet, "dynamic", {isSensor = true}) bullet.gravityScale = 0 end end spawnProj()

EDIT: I bought SSK2 Lite and I will be trying to solve this problem now.