I have a hitbox system in my experience, and it works fine when it’s small, but when the hitbox is bigger it can miss some characters. (objects)
Clip of said event:
(The visualization of the hitbox you see uses the Region3’s CFrame and Size which it provides.)
Script:
(Please excuse the horrendous formatting and generally horrendous choices, this script is somewhat old.)
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
local con= Signal.new()
local connection= con:Connect(Callback)
local Push = 1.15
local RootPart = Character:FindFirstChild("HumanoidRootPart")
--local s = (Part.CFrame * posandsize[1] + Humanoid.MoveDirection * Push).Position
local s
local Velocity = CFrame.lookAt(RootPart.Position, RootPart.Position + RootPart.Velocity).LookVector
if RootPart.Velocity.Magnitude <= 1 then
Velocity = Vector3.new(0,0,0)
else
local Timer = 10
local basevel = Velocity * (RootPart.Velocity.Magnitude / 10)
local Distance = ((Part.CFrame * posandsize[1] + (basevel * (Humanoid.WalkSpeed / 3))).Position - RootPart.Position).Magnitude
if Distance >= 40 then
Velocity = Velocity * (Distance / 45)
else
Velocity = (Velocity * (Distance / Division) ) + (Humanoid.MoveDirection / 4)
end
end
if Info.Prediction == true then
s = (Part.CFrame * posandsize[1] + (Velocity * (Humanoid.WalkSpeed / 3))).Position
else
s = (Part.CFrame * posandsize[1]).Position
end
local s2
local isNum = false
if typeof(posandsize[2]) == "Vector3" then
s2 = Vector3.new(posandsize[2].X / 2, posandsize[2].Y / 2, posandsize[2].Z / 2)
else
isNum = true
s2 = Vector3.new(posandsize[2] / 2, posandsize[2] / 2, posandsize[2] / 2)
end
local region3 = Region3.new(
( s +(s2 * -1)),
s + s2
)
if isNum == true then
if Studio then
ReplicatedStorage.Remotes.Client:FireAllClients("VisualizeHitbox",region3.CFrame, posandsize[2], Time)
end
else
if Studio then
ReplicatedStorage.Remotes.Client:FireAllClients("VisualizeHitbox",region3.CFrame, region3.Size, Time)
end
end
local them_all = workspace:FindPartsInRegion3WithIgnoreList(region3,{Character,workspace.Effects})
for i,v in pairs(them_all) do
if v:IsDescendantOf(workspace.Entities) then
local Humanoid = v.Parent:FindFirstChild("Humanoid")
if Humanoid then
print(Humanoid.Parent.Name)
if table.find(Characters,Humanoid.Parent) then
else
table.insert(Characters,Humanoid.Parent)
end
end
end
end
for i,v in pairs(Characters) do
local Humanoid = v:FindFirstChild("Humanoid")
if Humanoid then
if table.find(HitPeople,v) then
else
table.insert(HitPeople,v)
con:Fire(Humanoid)
end
end
end
coroutine.wrap(function()
task.wait(Time)
connection:Disconnect()
end)()