For my asymmetrical game (how original I know) I want to have hitboxes similar to that of Forsaken’s or like Pwned By 14:00, with how multiple hitboxes are spawned with one swing, and the code that I have so gracefully borrowed from DoomHammerYT does this correctly. However the system doesn’t account for velocity, which is the main issue, as the hitboxes lags behind the player while moving and the hitboxes get thrown if the player turns too fast.
The 3 lines of code above from Adi_DK is a solution that works for forsaken, but attempting to insert the code into the hitbox script doesn’t work, as I believe that the way the createHitbox function actually creates the hitboxes, attempting to combine the lines on top, is more difficult than I thought it would be.
Is there a simpler way to either make the hitboxes’s offset value adapt to velocity, or a way to combine the code?
The solution that I currently have is just an extremely simple and quite terrible, increasing the offset when a certain speed is reached, which still produces the issue of the hitboxes getting thrown when turning, and the hitboxes generally being disjointed
local pingOffset = 6.5 - 10 * math.clamp(player:GetNetworkPing(), 0, 0.3)
local velocityOffset = hitboxPart.CFrame:VectorToObjectSpace(primaryPart.AssemblyLinearVelocity)
hitboxPart.CFrame *= CFrame.new(velocityOffset / pingOffset)
-- the code i have no idea how to implement above
-- above code by Adi_DK
-- beneath code by DoomHammerYT
local function createHitbox(damage, size, offset, hrp, hitboxes, touchedTable)
local hitbox = Instance.new("Part")
hitbox.CanCollide = false
hitbox.Transparency = 0.75
hitbox.Size = size
hitbox.Parent = workspace
hitbox.CFrame = hrp.CFrame * CFrame.new(offset)
hitbox.Anchored = true
table.insert(hitboxes, hitbox)
local touchedParts = workspace:GetPartBoundsInBox(hitbox.CFrame, hitbox.Size)
for i, part in touchedParts do
table.insert(touchedTable, part)
end
end
m1Event.OnServerEvent:Connect(function(player, damage, size, offset, startup, Time, increment)
task.wait(startup) -- startup time
local hitboxes = {}
local touchedParts = {}
local damagedPlayers = {}
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")
local breakLoop = false
for i = 1, math.floor(Time / increment), 1 do
createHitbox(damage, size, offset, hrp, hitboxes, touchedParts)
for i, part in touchedParts do
if table.find(hitboxes, hitboxes[part]) or table.find(damagedPlayers, damagedPlayers[part.Parent.Name]) or not part.Parent:FindFirstChild("Humanoid") then
table.remove(touchedParts, touchedParts[part]) -- removes hitboxes, non-charcater objects, and anything already damaged
else
if part.Name == "playerHitbox" and part.Parent.Name ~= character.Name then
table.insert(damagedPlayers, part.Parent.Name)
part.Parent:FindFirstChild("Humanoid"):TakeDamage(damage)
breakLoop = true -- once hit it will stop casting the hitboxes
end
end
end
table.clear(touchedParts)
task.wait(increment)
if breakLoop then break end
end
for i, hitbox in hitboxes do
hitbox:Destroy()
end
end)