So I was changing my hit detection system for my melee weapon to use raycast instead of .Touched(), and I’ve run into a problem.
I’m trying to have it so it raycasts between the position of the attachment (multiple attachment on blade of weapon for positions of rays) in the previous step, but I’m having trouble figuring out a good way to do that.
Code:
local oldPos = Vector3.new()
Run.Stepped:Connect(function()
if tool.Blade:FindFirstChild("Swinging") then
for i, v in pairs(tool.BodyAttach:GetChildren()) do
if v.Name == "Ray" then
local origin = v.WorldPosition
local direction = oldPos - v.WorldPosition
local params = RaycastParams.new()
params.FilterDescendantsInstances = {plr.Character, workspace.WeaponsIgnore, tool}
params.IgnoreWater = true
local raycast = workspace:Raycast(origin, direction, params)
-- Part to visualize raycast.
local part = Instance.new("Part")
part.Anchored = true
part.Size = Vector3.new(0.05, 0.05, (oldPos - origin).Magnitude)
part.CFrame = CFrame.lookAt(oldPos, origin) * CFrame.new(0, 0, -(oldPos - origin).Magnitude/2)
part.Material = "Neon"
part.CanCollide = false
part.Transparency = 0.6
part.Parent = workspace.WeaponsIgnore
game:GetService("Debris"):AddItem(part, 0.1)
oldPos = v.WorldPosition
end
end
end
end)
(This is on the server)
So currently, this is what it currently looks like:
And this is what it should look like:
So what it does right now is looping through the attachments, and raycast between those attachments because oldPos is the position of the previous attachment in a way.(?) What I want it do do is, for each attachment, raycast between the previous position of the attachment (the variable, “oldPos”) and the current position of the attachment.