SO I’m using the joystick_lib.lua and the code below to move a boxed tank with the joystick. This works perfectly fine and as intended. My issue is spawning bullets in front of the box tank which I’m calling Avatar and getting it to fire as long as I am moving the tank around with the joystick.
Really if you can help me understand how to make the bullets go in the direction the tank is facing I could do the rest. The code right now works but the bullet does not follow the tank thus it fires from a fixed location on the screen. If I add the bullets to the same display group as the tank then everything gets messed up. Thanks for any help!
[lua]local jstick1
local laserFire1
myJoystick1 = joystick.NewStick(
{
x = 40,
y = 300,
thumbSize = 12,
borderSize = 42,
snapBackSpeed = .75,
R = 255,
G = 255,
B = 255
} )
–
jstick1 = function ( event )
myJoystick1:move(avatar1Group, avatar1speed, true)
avatar1Group:setReferencePoint(display.CenterReferencePoint);
laserFire1()
end
Runtime:addEventListener(“enterFrame”, jstick1)
–
Avatar = display.newImageRect(“assets/box_tank_1.png”,40,40)
Avatar.x,Avatar.y = _W,119
physics.addBody(Avatar, “dynamic”, {friction = 5.5, bounce = 0,radius = 17} )
Avatar.myName = “Avatar”
Avatar.yScale = -1
avatar1Group:insert(Avatar)
–
laserFire1 = function( e )
print(“Firing Lasers”)
local laser1 = display.newRect(0,0,10,1)
laser1.x,laser1.y = Avatar.x, Avatar.y - Avatar.height
physics.addBody(laser1)
laser1.isBullet = true
laser1:applyLinearImpulse( 20, 20, laser1.x,laser1.y)
end
[/lua] [import]uid: 53149 topic_id: 34124 reply_id: 334124[/import]