How to make a trail with parts?

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?

3 Likes

They recently released Shapecasts, maybe that can help you out.
Or make your hitbox a little larger that the actual blade size, like a .5 stud diameter instead of .05 studs.

1 Like

this seems to work very well, i never knew they added shapecasts this is very useful. thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.