Hi guys, I am currently testing some ‘area’ detection using the part corners to detect if it’s inside/out other parts corners.
But when rotating the box part it doesn’t works anymore.
Code;
Ppart is the moving part, transparent is the box
local x2 = {};
local Ppart = workspace.furniture;
local Box = workspace.box;
while wait(.1) do
local x = {}
local CornerX1 = Ppart.CFrame * CFrame.new(Ppart.Size.X/2,Ppart.Size.Y/2,Ppart.Size.Z/2)
local CornerX2 = Ppart.CFrame * CFrame.new(Ppart.Size.X/2,Ppart.Size.Y/2,-Ppart.Size.Z/2)
local CornerX3 = Ppart.CFrame * CFrame.new(-Ppart.Size.X/2,Ppart.Size.Y/2,Ppart.Size.Z/2)
local CornerX4 = Ppart.CFrame * CFrame.new(-Ppart.Size.X/2,Ppart.Size.Y/2,-Ppart.Size.Z/2)
local CornerTopX1 = Ppart.CFrame * CFrame.new(Ppart.Size.X/2,-Ppart.Size.Y/2,Ppart.Size.Z/2)
local CornerTopX2 = Ppart.CFrame * CFrame.new(Ppart.Size.X/2,-Ppart.Size.Y/2,-Ppart.Size.Z/2)
local CornerTopX3 = Ppart.CFrame * CFrame.new(-Ppart.Size.X/2,-Ppart.Size.Y/2,Ppart.Size.Z/2)
local CornerTopX4 = Ppart.CFrame * CFrame.new(-Ppart.Size.X/2,-Ppart.Size.Y/2,-Ppart.Size.Z/2)
table.insert(x,CornerX1)
table.insert(x,CornerX2)
table.insert(x,CornerX3)
table.insert(x,CornerX4)
workspace.ShotPart:ClearAllChildren()
for i,v in pairs(x) do
local part = Instance.new("Part")
part.Size = Vector3.new(.5,.5,.5)
part.Material = Enum.Material.Neon;
part.BrickColor = BrickColor.Green()
part.CFrame = v;
part.Shape = Enum.PartType.Ball;
part.Parent = workspace.ShotPart;
part.Anchored = true;
part.Name = v == CornerX1 and 'cornerX1' or v == CornerX2 and 'CornerX2' or v == CornerX3 and 'CornerX3' or v == CornerX4 and 'CornerX4'
end
local BoxX1 = Box.CFrame * CFrame.new(Box.Size.X/2,Box.Size.Y/2,Box.Size.Z/2)
local BoxX2 = Box.CFrame * CFrame.new(Box.Size.X/2,Box.Size.Y/2,-Box.Size.Z/2)
local BoxX3 = Box.CFrame * CFrame.new(-Box.Size.X/2,Box.Size.Y/2,Box.Size.Z/2)
local BoxX4 = Box.CFrame * CFrame.new(-Box.Size.X/2,Box.Size.Y/2,-Box.Size.Z/2)
local BoxTopX1 = Box.CFrame * CFrame.new(Box.Size.X/2,-Box.Size.Y/2,Box.Size.Z/2)
local BoxTopX2 = Box.CFrame * CFrame.new(Box.Size.X/2,-Box.Size.Y/2,-Box.Size.Z/2)
local BoxTopX3 = Box.CFrame * CFrame.new(-Box.Size.X/2,-Box.Size.Y/2,Box.Size.Z/2)
local BoxTopX4 = Box.CFrame * CFrame.new(-Box.Size.X/2,-Box.Size.Y/2,-Box.Size.Z/2)
local Xbool = (CornerX1.Position.X <= BoxX1.Position.X and CornerX1.Position.X >= BoxX4.Position.X) and (CornerX3.Position.X >= BoxX3.Position.X and CornerX3.Position.X <= BoxX2.Position.X) and (CornerX2.Position.X <= BoxX2.Position.X and CornerX2.Position.X >= BoxX4.Position.X) and (CornerX4.Position.X >= BoxX4.Position.X and CornerX4.Position.X <= BoxX2.Position.X)
local Zbool = (CornerX1.Position.Z <= BoxX1.Position.Z and CornerX1.Position.Z >= BoxX4.Position.Z) and (CornerX3.Position.Z <= BoxX3.Position.Z and CornerX3.Position.Z >= BoxX4.Position.Z) and (CornerX2.Position.Z >= BoxX2.Position.Z and CornerX2.Position.Z <= BoxX3.Position.Z) and (CornerX4.Position.Z >= BoxX4.Position.Z and CornerX4.Position.Z <= BoxX3.Position.Z)
if (Xbool and Zbool) then
Ppart.BrickColor = BrickColor.Green();
else
Ppart.BrickColor = BrickColor.Red()
end
end