hi, i am currently developing a melee fighting game for vr, and have been having a lot of trouble with hit detection. i need to detect if the player’s blade is blocked by another blade, but the problem is that the weapons are thin, and .touched is not consistent because of frame rate. i am also not able to use raycast, as i would need to do way too many raycast all along the blade, which would impact performance on the oculus quest.
so what i have thought of is to use parts, and create a part to cover the distance the blade moves from the previous frame to the current frame, and then use GetPartsInPart to get the parts in that. this would essentially just be a trail made of parts.
here is the code i came up with for this:
local prevBladePos = weapon.Blade.Position
local function HitDetection(hit)
local distance = (prevBladePos-weapon.Blade.Position).Magnitude
local hitbox = Instance.new("Part", workspace)
hitbox.Anchored = true
hitbox.CanCollide = false
hitbox.Color = Color3.fromRGB(255, 0, 0)
hitbox.Material = "Neon"
hitbox.Transparency = 0.5
hitbox.Parent = workspace
hitbox.Size = Vector3.new(weapon.Blade.Size.Y, 0.05, distance)
hitbox.CFrame = CFrame.new(weapon.Blade.Position, prevBladePos) * CFrame.new(0, 0, -distance/2)
prevBladePos = weapon.Blade.Position
end
but this does not work as i want it to, and i can not figure out a better way to do it. any help?