WorldRoot:Raycast bug?

I want to raycast from a part’s position directly downwards and if any part is hit then it would generate a second part visualizing the hit.
I’m not sure why but it is acting like a lerp function? It generates parts from an offset and those parts get closer and closer to the casting position.
https://gyazo.com/0269d5a902af7362599a7f2be0896d3e
https://gyazo.com/64c7a050ecda8d0401f671c42f9aca87
https://gyazo.com/923730fec2a23ead6b083e56aa5bc9d3
I’ll try solving it, but any reply could potentially speed up the process, in which case I’d be very grateful.

while true do
	local params = RaycastParams.new()
	params.FilterDescendantsInstances = {script.Parent}
	params.FilterType = Enum.RaycastFilterType.Blacklist
	local raycastAttempt = workspace:Raycast(script.Parent["1"].Position, script.Parent["1"].Position + (Vector3.fromNormalId(Enum.NormalId.Bottom) * 10), params)
	
	if raycastAttempt then
	print("Hit!")
		print("Raycast_Attempt: ",raycastAttempt.Position)
		print("Start_Point: ", script.Parent["1"].Position)
		print("Finish_Point: ",script.Parent["1"].Position + (Vector3.fromNormalId(Enum.NormalId.Bottom) * 10))
		local part = Instance.new("Part")
		part.CFrame = CFrame.new(raycastAttempt.Position)
		part.Name = "Visualization"
		part.Size = Vector3.new(1,1,1)
		part.Anchored = true
		part.CanCollide = false
		part.Material = raycastAttempt.Material
		part.Color = Color3.new(255,0,0)
		part.Parent = workspace
	end
	wait(1)
end

The second argument is a direction, not a position, relative to the origin of the ray cast. However you treated it as relative to the world origin (0, 0, 0).

So just do

workspace:Raycast(script.Parent["1"].Position, Vector3.new(0, -1, 0)*10, params)
2 Likes

I was stuck on this issue for about 2.5 hours now overthinking it. I’ll try not doing the same silly mistake next time.
Thank you for the help (:

And please click the “Solution” button on @sjr04’s post to mark this post as solved.

1 Like

Did it, thanks for reminding me. (: