Raycast is being slow and late

local endHitbox = false
task.spawn(function()
	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	raycastParams.IgnoreWater = false
	raycastParams.FilterDescendantsInstances = {newFirePart, workspace.Ignore, workspace.Characters}

	--[[local overlapParams = OverlapParams.new()
	overlapParams.FilterType = Enum.RaycastFilterType.Blacklist
	overlapParams.FilterDescendantsInstances = {workspace.Ignore}]]
		
	while not endHitbox do
		raycastParams.FilterDescendantsInstances = {workspace.Ignore, workspace.Characters}
		--overlapParams.FilterDescendantsInstances = {workspace.Ignore}

		local rayResult = workspace:Raycast(newFirePart.Position, Vector3.new(0, -1.5, 0), raycastParams)
		if rayResult then
			newFirePart.Anchored = true
		else
			newFirePart.Anchored = false
		end
		--[[local resultArray = workspace:GetPartsInPart(newFirePart, overlapParams)
		newFirePart.Anchored = false
		for i, v in pairs(resultArray) do
			if v:IsDescendantOf(workspace.Characters) then continue end
			newFirePart.Anchored = true
		end]]
		runService.PreSimulation:Wait()
	end
end)

I also tried to use :GetPartsInPart() and .Touched its just reacts to the part too slowly and late

This is #help-and-feedback:scripting-support. We can’t help you if you don’t show some of your scripts.

sorry, now i added a piece of my code

Raycasts will naturally look slow when it’s done on the server, if that’s how you’re doing it.

An issue with the method you’ve done, your raycasting method leaves holes with each frame/ pre-render so your raycast would kind of look like this each step: (Be blinded by the white background)

So if your object gains enough velocity, you’ll get bigger and bigger gaps between each raycast, so you’ll probably want to log the previous position and raycast from previous to current, and while this might be look fairly janky you might want to set the position of the part to the raycast.Position.

You can get a little deeper with raycasting methods and predict where the object will be the next frame, but you’ll need to pay attention to the parts predicted distance traveled with X velocity and the actual distance traveled but I digress.

1 Like

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