-- // Public Methods \\ --

function CastVisualiser:Hide()
	self.CastOriginPart.Parent = nil
end

function CastVisualiser:Raycast(Origin: Vector3, Direction: Vector3, RaycastParameters: RaycastParams?)
	local self: CastVisualiserPrivate = self
	
	local Cast = self.WorldRoot:Raycast(Origin, Direction, RaycastParameters)
	if not Cast then
		self:Hide()
		return
	end
	
	self.CastOriginPart.CFrame = CFrame.lookAt(Origin, Cast.Position)

	self.LineVisual.Length = Cast.Distance - CONE_HEIGHT
	self.ConeVisual.CFrame = CFrame.new(0, 0, -Cast.Distance)
	
	self.BoxVisual.Visible = false
	self.SphereVisual.Visible = false
	
	self.CastOriginPart.Parent = self.WorldRoot:FindFirstChild("Terrain") or self.WorldRoot
end


function CastVisualiser:Blockcast(CF: CFrame, Size: Vector3, Direction: Vector3, RaycastParameters: RaycastParams?)
	local self: CastVisualiserPrivate = self
	
	local Cast = self.WorldRoot:Blockcast(CF, Size, Direction, RaycastParameters)
	if not Cast then
		self:Hide()
		return
	end
	
	local FinalPos = CF.Position + (Direction.Unit * Cast.Distance)
	
	self.CastOriginPart.CFrame = CFrame.lookAt(CF.Position, FinalPos)
	
	self.LineVisual.Length = Cast.Distance - CONE_HEIGHT
	self.ConeVisual.CFrame = CFrame.new(0, 0, -Cast.Distance)
	
	self.BoxVisual.CFrame = CFrame.new(0, 0, -Cast.Distance)
	self.BoxVisual.Size = Size
	
	self.BoxVisual.Visible = true
	self.SphereVisual.Visible = false
	
	self.CastOriginPart.Parent = self.WorldRoot:FindFirstChild("Terrain") or self.WorldRoot
end


function CastVisualiser:SphereCast(Origin: Vector3, Radius: number, Direction: Vector3, RaycastParameters: RaycastParams?)
	local self: CastVisualiserPrivate = self
	
	local Cast = self.WorldRoot:Spherecast(Origin, Radius, Direction, RaycastParameters)
	if not Cast then
		self:Hide()
		return
	end
	
	local FinalPos = Origin + (Direction.Unit * Cast.Distance)

	self.CastOriginPart.CFrame = CFrame.lookAt(Origin, FinalPos)

	self.LineVisual.Length = Cast.Distance - CONE_HEIGHT
	self.ConeVisual.CFrame = CFrame.new(0, 0, -Cast.Distance)
	
	self.SphereVisual.CFrame = CFrame.new(0, 0, -Cast.Distance)
	self.SphereVisual.Radius = Radius
	
	self.SphereVisual.Visible = true
	self.BoxVisual.Visible = false
	
	self.CastOriginPart.Parent = self.WorldRoot:FindFirstChild("Terrain") or self.WorldRoot
end
