Hello everyone!
Im making a 2D engine for my game.
This script works… but since it uses AbsoluteSize and AbsolutePosition, it sees the hitbox as way bigger then it actually should be. When the instance “bullet” hits the “enemy” it should delete the enemy. However, there is no way to miss because the hitbox is so big. Any help?
bullet:GetPropertyChangedSignal("Position"):Connect(function() -- checks for pos changing
local hitbox = bullet
local pos1, size1 = enemy.AbsolutePosition, enemy.AbsoluteSize;
local pos2, size2 = hitbox.AbsolutePosition, hitbox.AbsoluteSize;
local top = (pos1.Y) - (pos2.Y)
local bottom = (pos2.Y) - (pos1.Y)
local left = (pos1.X) - (pos2.X)
local right =(pos2.X) - (pos1.X)
local touching = false
if top < (size1.Y) and bottom < (size1.Y) and left < (size1.X) and right < (size1.X) then
bullet:Destroy()
enemy:Destroy()
end
return touching
end)
bullet:GetPropertyChangedSignal("Position"):Connect(function() -- checks for pos changing
local hitbox = bullet
local pos1, size1 = enemy.AbsolutePosition, enemy.AbsoluteSize;
local pos2, size2 = hitbox.AbsolutePosition, hitbox.AbsoluteSize*0.5;
local top = (pos1.Y) - (pos2.Y)
local bottom = (pos2.Y) - (pos1.Y)
local left = (pos1.X) - (pos2.X)
local right =(pos2.X) - (pos1.X)
local touching = false
if ((top < (size1.Y)) and (bottom < (size1.Y)) and (left < (size1.X)) and (right < (size1.X))) then
bullet:Destroy()
enemy:Destroy()
end
return touching
end)