what should i need to do if i have to fire arrow at any angle say 45,60,30 ? i know the center pos of arrow and its angle now how to fire in that direction
If you have angle, you only need to calculate the vectors based on the angle:
local xVect = -math.sin(self.mySphere.body:getAngle())*strength
local yVect =math.cos(self.mySphere.body:getAngle())*strength
self.mySphere.body:applyLinearImpulse(xVect, yVect, self.mySphere:getX(),self.mySphere:getY())
depending on your original image, how it is rotated, you may need to apply offset angle, like your arrows image is pointing to the right, rotate it for 90 degrees by applying -math.pi/2 to make the default direction up
local xVect = -math.sin(self.mySphere.body:getAngle()-math.pi/2)*strength
local yVect =math.cos(self.mySphere.body:getAngle()-math.pi/2)*strength
self.mySphere.body:applyLinearImpulse(xVect, yVect, self.mySphere:getX(),self.mySphere:getY())
Comments