Unable to cast RaycastParams to Vector3

hola he tratado de hacer un detector si la cabeza de el jugador esta mirando el objeto bajo un rango de vision
pero cuando lo intento me sale el error de
“Unable to cast RaycastParams to Vector3”

My code here:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local head = char:WaitForChild("Head")

while wait() do
	local test = workspace:WaitForChild("raytest")
	if test then
		local params = RaycastParams.new()
		params.FilterDescendantsInstances = {test}
		params.FilterType = Enum.RaycastFilterType.Whitelist
--------Error here
		local raycast = workspace:Raycast(head.Position * CFrame.Angles(0, math.rad(90), 0).LookVector * 100, params)
		if raycast then
			local object = raycast.Instance
			if object then

I want to do something similar to this in 2D or 3D the raycast:

There are 3 parameters to Raycasting. Origin, End, and parameters. So, it should look like this:

local raycast = workspace:Raycast(head.Position, head.Position * CFrame.Angles(0, math.rad(90), 0).LookVector * 100, params
1 Like

that works but I mean how can I make a raycas type like that?

You’re better off using the vector3 dot product method. Dot product method is a more optimal way to provide field of view for an object / npc.

1 Like