Raycast cannot seem to detect anything but baseplate

I’m getting the hitpos and the part position but not the normals

part = script.Parent

part.Touched:Connect(function(hit)
	wait()
	print(hit)
	local hitpos = hit.Position
	print(hitpos)
	
	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	raycastParams.FilterDescendantsInstances = {workspace.Terrain}
	raycastParams.IgnoreWater = true
	local raycastResult = workspace:Raycast(part.Position, hitpos, raycastParams)
	local thing = nil
	-- Interpret the result
	if raycastResult then
		print("Object/terrain hit:", raycastResult.Instance:GetFullName())
		print("Hit position:", raycastResult.Position)
		print("Surface normal at the point of intersection:", raycastResult.Normal)
		print("Material hit:", raycastResult.Material.Name)
		
	else
		print("Nothing was hit!")
	end

end)

The second parameter of workspace:Raycast() should be a direction vector, so use (hitpos - part.Position)

why is (hitpos - part.position) a direction vector?

it shows the direction from part.Position to hitpos rather than a 3d position in the world

1 Like