Shooting balls

I have an arrow kinda thing…it will keep rotating 360 degree…then when i click the screen, it should shoot balls wherever my arrow is pointing…

Its something like maths thing i suppose

Yep.  Sounds like a math thing, wait is there a question in there somewhere? https://forums.coronalabs.com/topic/55780-ask-a-better-question-get-a-better-answer/

Anyways, I have a many, many shooting examples, here are just three:

PS - I poked fun to make a point, not just because I’m mean  :o.  Please ask better questions, or at least ask one.  Don’t just post ‘train of thought’ stuff and expect answers.  Your effort should be demonstrably as great as the effort of those who answer you.

You don’t need SSK for the examples I gave.   You can use the math2d plugin instead:

https://marketplace.coronalabs.com/plugin/math2d

Nothing helped me. 

Everything you need is there, you’ve just got to read it. People are going to give up trying to help you when you don’t even try.

Here’s a working example.

local physics = require('physics') physics.start() physics.setGravity(0, 0) physics.setDrawMode( "normal") --[[Math Lib: http://developer.coronalabs.com/code/maths-library]]-- -- returns the degrees between (0,0) and pt -- note: 0 degrees is 'east' function angleOfPoint( pt ) local x, y = pt.x, pt.y local radian = math.atan2(y,x) --print('radian: '..radian) local angle = radian\*180/math.pi --print('angle: '..angle) if angle \< 0 then angle = 360 + angle end --print('final angle: '..angle) return angle end -- returns the degrees between two points -- note: 0 degrees is 'east' function angleBetweenPoints( a, b ) local x, y = b.x - a.x, b.y - a.y return angleOfPoint( { x=x, y=y } ) end -- rotates a point around the (0,0) point by degrees -- returns new point object function rotateTo( point, degrees ) local x, y = point.x, point.y local theta = math.rad(degrees) local pt = { x = x \* math.cos(theta) - y \* math.sin(theta), y = x \* math.sin(theta) + y \* math.cos(theta) } return pt end --[[-------------------------------------]]-- function fireBullet(source, angle) local bullet = display.newRect( 0,0 , 10,2 ) bullet.x, bullet.y, bullet.rotation = source.x, source.y, angle physics.addBody( bullet ) local direction = rotateTo( {x=10,y=0}, angle ) bullet:applyForce( direction.x, direction.y, bullet.x, bullet.y ) -- you might want to shorten the direction values end local ship = display.newRect( 50, 50, 20, 100 ) ship.x, ship.y = 200, 200 function touch( e ) local angle = angleBetweenPoints( ship, e ) ship.rotation = angle-90 -- because .rotation is not 'east' print('angle', angle) if (e.phase == "began") then elseif (e.phase == "moved") then else fireBullet(ship, angle) end return true end Runtime:addEventListener("touch",touch)

Needs modification of course

Yep.  Sounds like a math thing, wait is there a question in there somewhere? https://forums.coronalabs.com/topic/55780-ask-a-better-question-get-a-better-answer/

Anyways, I have a many, many shooting examples, here are just three:

PS - I poked fun to make a point, not just because I’m mean  :o.  Please ask better questions, or at least ask one.  Don’t just post ‘train of thought’ stuff and expect answers.  Your effort should be demonstrably as great as the effort of those who answer you.

You don’t need SSK for the examples I gave.   You can use the math2d plugin instead:

https://marketplace.coronalabs.com/plugin/math2d

Nothing helped me. 

Everything you need is there, you’ve just got to read it. People are going to give up trying to help you when you don’t even try.

Here’s a working example.

local physics = require('physics') physics.start() physics.setGravity(0, 0) physics.setDrawMode( "normal") --[[Math Lib: http://developer.coronalabs.com/code/maths-library]]-- -- returns the degrees between (0,0) and pt -- note: 0 degrees is 'east' function angleOfPoint( pt ) local x, y = pt.x, pt.y local radian = math.atan2(y,x) --print('radian: '..radian) local angle = radian\*180/math.pi --print('angle: '..angle) if angle \< 0 then angle = 360 + angle end --print('final angle: '..angle) return angle end -- returns the degrees between two points -- note: 0 degrees is 'east' function angleBetweenPoints( a, b ) local x, y = b.x - a.x, b.y - a.y return angleOfPoint( { x=x, y=y } ) end -- rotates a point around the (0,0) point by degrees -- returns new point object function rotateTo( point, degrees ) local x, y = point.x, point.y local theta = math.rad(degrees) local pt = { x = x \* math.cos(theta) - y \* math.sin(theta), y = x \* math.sin(theta) + y \* math.cos(theta) } return pt end --[[-------------------------------------]]-- function fireBullet(source, angle) local bullet = display.newRect( 0,0 , 10,2 ) bullet.x, bullet.y, bullet.rotation = source.x, source.y, angle physics.addBody( bullet ) local direction = rotateTo( {x=10,y=0}, angle ) bullet:applyForce( direction.x, direction.y, bullet.x, bullet.y ) -- you might want to shorten the direction values end local ship = display.newRect( 50, 50, 20, 100 ) ship.x, ship.y = 200, 200 function touch( e ) local angle = angleBetweenPoints( ship, e ) ship.rotation = angle-90 -- because .rotation is not 'east' print('angle', angle) if (e.phase == "began") then elseif (e.phase == "moved") then else fireBullet(ship, angle) end return true end Runtime:addEventListener("touch",touch)

Needs modification of course