[lua] function shoot:tap(e) local bullet = display.newImageRect('bullet.png', 15, 10) bullet.x = player.x bullet.y = player.y bullet.name = 'bullet' physics.addBody(bullet) bullet.isSensor = true audio.play(GunShot) -- rotation local enterFrame enterFrame = function( event ) local position = puggle.mouse:getPosition( true ) local angle = puggle.maths:angleBetweenVectors( bullet, position ) player.rotation = angle - 90 local vector = puggle.maths:vectorFromAngle( angle ) bullet.x = bullet.x + vector.x bullet.y = bullet.y + bullet.y bullet:toBack() gameBg:toBack() Runtime:addEventListener( "enterFrame", enterFrame ) [/lua]
Hi all, I am currently trying to produce bullets and shoot them in the direction of my mouse cursor. They currently spawn on the players position and the image of the bullet appears but it does not move. I have tried a few methods seen on these forums posts but nothing worked yet. Should i use some sort applyForce code or is there an easier way to move this. It is not linear movement. My player can rotate 360 degrees just in case i confuse anyone. These bullets will also be shot at an enemy so I assume its easier to give the enemy collision and not the bullets themselves. Thanks in advance.