Well I am trying to make a Hit detection system for a sword using attachments and Raycasting,
In-short, I basically continuously Raycast, during the swing, from the attachments current position to its last position. (screen shot included below)
My issue is that the EVEN THOUGH I have my Raycasts visualized through parts, I’ve noticed that even when my parts don’t go anywhere near the Rigs I’m testing on, it still registers as a hit…
Here’s a screen shot of the in-game visualized Raycasts:
Now, I had set up print statements to see what I was hitting, here they are:
As you can see, even though the Raycasts go no where near rig1 or rig3, they seem to be getting hit somehow, I’m just wondering why this is happening and how to fix it, thank you!
Here’s loop for the actual Raycasting during the swing:
slicing = true
while slicing do
if waitSwitch == false then
waitSwitch = true
else
task.wait()
waitSwitch = false
end
for _, att in ipairs(bladeAttachments) do
local attNum = string.sub(att.Name,4,4)
local attNum = tonumber(attNum)
local origin = bladeAttachments[attNum].WorldPosition
local direction = lastOrigins[attNum]
local distance = (origin-direction).Magnitude
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {workspace.Map, workspace.Fx, char}
local result = workspace:Raycast(origin, direction, params)
if result then
table.insert(partsHit, result)
end
lastOrigins[attNum] = origin
if debugMode then
local debugPart = Instance.new("Part")
debugPart.Color = Color3.fromRGB(255, 0, 4)
debugPart.Material = Enum.Material.ForceField
debugPart.Size = Vector3.new(0.2,0.2,4)
debugPart.CFrame = CFrame.lookAt(origin, direction)*CFrame.new(0,0, -distance/2)
debugPart.Anchored = true
debugPart.CanCollide = false
debugPart.Parent = workspace.Fx
game.Debris:AddItem(debugPart, 2)
end
end
--print("slicing!")
end
end)
Help is appreciated.