Bullet's not working
Posted: Sat Jun 06, 2009 2:20 am
I started playing with löve a few days ago and was surprised how easy and intuitive it is!
So I decided to learn more about it by programming an asteroids clone. Everything has gone smoothly until I tried creating the bullets - they don't move away from the ship, even when I turn the initial velocity on them way up. The bullets do start moving, however, when something bumps into them.
I'm sure I'm just making some obvious and stupid mistake, but I thought I'd post my code up here for help. The bullet code is in the /classes/ship.lua file, and I think the pertinent code is in the "Ship:shoot" function on line 58:
Here's the full code
So I decided to learn more about it by programming an asteroids clone. Everything has gone smoothly until I tried creating the bullets - they don't move away from the ship, even when I turn the initial velocity on them way up. The bullets do start moving, however, when something bumps into them.
I'm sure I'm just making some obvious and stupid mistake, but I thought I'd post my code up here for help. The bullet code is in the /classes/ship.lua file, and I think the pertinent code is in the "Ship:shoot" function on line 58:
Code: Select all
function Ship:shoot(dt)
local bullet_shape = love.physics.newCircleShape(self.bullet.body, 5)
bullet_shape:setData("bullet")
self.bullet.body:setBullet(true)
self.bullet.body:setMassFromShapes()
local radAngle = math.rad(self.body:getAngle())
local xSpeed = math.sin(radAngle) * 5000
local ySpeed = -math.cos(radAngle) * 5000
self.bullet.body:setPosition(self.body:getX() + math.sin(radAngle)*40, self.body:getY() - math.cos(radAngle)*40)
--self.bullet.body:setAngle(self.body:getAngle())
self.bullet.body:setVelocity(xSpeed, ySpeed)
end