Combining Raycast with Dotproduct

Hello!

I’m currently making a line of sight system and i got it to work in only one axis.

The reason is that im utilizing a single ray raycast and then i noticed that there is something called “DotProduct()”

How could i get to combine dotproduct into this code:

local part = script.Parent.Head
local rayDirection = part.CFrame.LookVector * 30

while task.wait() do
	local raycastResult = game:GetService("Workspace"):Raycast(part.Position, rayDirection)
	local params = RaycastParams.new()
	params.FilterType = Enum.RaycastFilterType.Blacklist
	params.FilterDescendantsInstances = script.Parent:GetChildren()
	if raycastResult and game.Players:GetPlayerFromCharacter(raycastResult.Instance.Parent) then
		print("found ".. raycastResult.Instance.Name)
	else
		print("wheres")
	end
end

(ik im using a outdated raycast system and using task.wait(), you can fix it if you want to)

Are you wanting the “widen” the line of sight from the part, or are you wanting to check if the part is in the player’s view if hit?

1 Like

I guess “widen” whatever that is supposed to be

I’m not entirely sure what you mean, but I’m guessing you want to try to establish a field of vision. If so this is useful:

You can find the angle between object1 and object2 using the dot product and compare it with an arbitrary max angle value.

I’m not really sure how you want to incorporate rays into this to be honest, unless you want something else.