fix: make weapons not collide with their creator

This commit is contained in:
Kazhnuz 2021-11-27 12:50:27 +01:00
parent b5f1728f1e
commit 789fa0adda
3 changed files with 15 additions and 7 deletions

View file

@ -21,6 +21,8 @@ function PhysicalActor:initPhysics(hitboxObj, isSolid)
self:setBounceFactor() self:setBounceFactor()
self:setFilter() self:setFilter()
self.ignoreList = {}
self:addUpdateFunction(self.autoMove) self:addUpdateFunction(self.autoMove)
end end
@ -28,12 +30,19 @@ function PhysicalActor:setBounceFactor(newBounceFactor)
self.bounceFactor = newBounceFactor or 0 self.bounceFactor = newBounceFactor or 0
end end
function PhysicalActor:ignore(item)
assert(item.creationID ~= nil, "creationID shouldn't be nil")
table.insert(self.ignoreList, item.creationID)
end
function PhysicalActor:setFilter() function PhysicalActor:setFilter()
-- Init the bump filter -- Init the bump filter
self.filter = function(item, other) self.filter = function(item, other)
if (other.owner == self) then if (other.owner == self) then
-- ignore every collision with our own hitboxes -- ignore every collision with our own hitboxes
return nil return nil
elseif (utils.table.contain(self.ignoreList, other.owner.creationID)) then
return nil
elseif (other.isSolid) then elseif (other.isSolid) then
return "slide" return "slide"
else else

View file

@ -18,7 +18,7 @@ function WeaponManager:shoot(x, y, z, dir)
local weaponData = weaponList[self.currentWeapon] local weaponData = weaponList[self.currentWeapon]
for i,coord in ipairs(weaponData.launch) do for i,coord in ipairs(weaponData.launch) do
self.player.obj.Weapon(self.player.world, x + coord[1], y + coord[2], z + coord[3], dir, weaponData) self.player.obj.Weapon(self.player.world, x + coord[1], y + coord[2], z + coord[3], dir, weaponData, self.player)
end end
end end

View file

@ -1,7 +1,7 @@
local Parent = require "game.modules.subgames.world.actors.parent" local Parent = require "game.modules.subgames.world.actors.parent"
local WeaponShot = Parent:extend() local WeaponShot = Parent:extend()
function WeaponShot:new(world, x, y, z, direction, data) function WeaponShot:new(world, x, y, z, direction, data, creator)
WeaponShot.super.new(self, world, "shot", x, y, z, 16, 8, 16, false) WeaponShot.super.new(self, world, "shot", x, y, z, 16, 8, 16, false)
self:setSprite("ringweapon", 0, 0) self:setSprite("ringweapon", 0, 0)
self.direction = direction self.direction = direction
@ -12,14 +12,13 @@ function WeaponShot:new(world, x, y, z, direction, data)
if (self.zsp ~= 0) then if (self.zsp ~= 0) then
self:setGravity(480*2) self:setGravity(480*2)
end end
print(self.xsp) self:ignore(creator)
end end
function WeaponShot:updateStart(dt) function WeaponShot:updateStart(dt)
print(self.xsp) if (self.xsp == 0) then
-- if (self.xsp == 0) then self:destroy()
-- self:destroy() end
-- end
end end
function WeaponShot:draw() function WeaponShot:draw()