Code: Select all
Object = require "classic"
Bullet = Object:extend()
function Bullet:new(world, shooter)
self.world = world
self.angle = shooter:getAngle()
self.x = (shooter:getX() -
(10 * math.sin(self.angle))) + (30 * math.cos(self.angle))
self.y = (shooter:getY() +
(10 * math.cos(self.angle))) + (30 * math.sin(self.angle))
self.distance = 500
end
function Bullet:fire()
local endX = self.x + (self.distance * math.cos(self.angle))
local endY = self.y + (self.distance * math.sin(self.angle))
self.world:rayCast(self.x, self.y, endX, endY, self.hit)
end
function Bullet:hit(fixture, x, y, xn, yn, fraction)
print("Looks like we hit something")
return 1
end
EDIT: I found the issue. I needed to declare the function self.hit as Bullet.hit, not Bullet:hit. Once I did that it returned the fixture properly.
Code: Select all
-- Fixed code
function Bullet.hit(fixture, x, y, xn, yn, fraction)
print("Looks like we hit something")
return 1
end