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

View file

@ -18,7 +18,7 @@ function WeaponManager:shoot(x, y, z, dir)
local weaponData = weaponList[self.currentWeapon]
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

View file

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