Shooting arrow

Dssi thanks for the answer.

I’ve applied those lines to my app (just in case somebody wants to use it too, its math.cos, math.sin on the local xForce,yForce and magicBullet:applyForce) but whenever i press, the arrow goes always a little bit to the bottom of the screen, and when I press in the upper section of the screen ( the arrow is initialized in the middle), the arrow goes to the middle, cant get past it. I know it might be something about a negative value but i don’t know what to change to do it. 

Tell me if you understand what i just said, if not i can make a simple graphic.

Thanks again

 I was in a rush so I may have left some more things out

above all I was foolish I didn’t ask where you will be initializing the arrow haha…

there are two things I missed

first you should turn Off gravity after you call physics.start()

by typing

physics.setGravity(0,0)

and I forgot to tell you how to set the initial location

so this is a script I tested and I gaurantee it  works

local physics = require(“physics”)

physics.start()
physics.setGravity(0,0)

local bulletGroup = display.newGroup()
 

local function touched(event)
if event.phase ==“began” then
local magicBullet = display.newImage(“image.png”)

local startX = 123 – startlocaations

local startY = 123

physics.addBody(magicBullet,“dynamic”)

**magicBullet.x = startX
magicBullet.y = startY
local atanVal = math.atan2(event.y - startX,event.x - startY)
local xForce,yForce = math.cos(atanVal)*(speed), math.sin(atanVal)*( speed )

magicBullet:applyForce(xForce,yForce,magicBullet.x,magicBullet.y)**

bulletGroup:insert(magicBullet)  – i reccomend you do this so you’ll be able to delete
end
end

Runtime:addEventListener(“touch”,touched)

I just started answering questions so my replies are pretty lame …sorry haha… :D  :D 

Thanks a lot! added it inside a for loop and it worked!

Only thing i’ve noticed is that if you want to use a different position where startX =/ startY you have to use 

local atanVal = math.atan2(event.y - startX,event.x - startY)

instead of 

local atanVal = math.atan2(event.y - startY,event.x - startX)

Thanks for all the help, i’ll totally need to re-read all those math books haha…

I would recommend:

http://www.amazon.com/Mathematics-Game-Developers-Development/dp/159200038X

or

http://www.amazon.com/Beginning-Math-Physics-Game-Programmers/dp/0735713901/ref=pd_sim_b_1

I tested this chunk of code for my self and it was very nice

One thing I would like to implement is that the arrow follows the sinus curve so it looks more natural

so it kinda points down when it false to the ground

and I´m also one of those coders who says “I wish I didn´t sleep through the math lessons at school”

I started with:

physics.setGravity(0,4) --so it falls down after a while

local speed = -20 --this could be calculated on the length between self and target

magicBullet.isFixedRotation = false  --but after this I got lost

hmm, that’s strange it may have something to do with the view My scripts are based on vertical so , anyway gladit works

I was thinking like this:

http://snag.gy/TB2xj.jpg

Anyone?

I was thinking like this:
http://snag.gy/TB2xj.jpg

Good timing, i’m having the same problem…

Bumping this thread.

Hi I think this is what you guys are looking for.

http://developer.coronalabs.com/code/arrow-basics

Cheers

Anyone?

I was thinking like this:
http://snag.gy/TB2xj.jpg

Good timing, i’m having the same problem…

Bumping this thread.

Hi I think this is what you guys are looking for.

http://developer.coronalabs.com/code/arrow-basics

Cheers