I want to create an FOV visualiser. I have a dot product region that I want to display/visualise, to show where the npc can see. For example in the image, a line from the player at a 0.3 dot product value from the character (apologies for terminology ) and another at -0.3.

I feel like there’s a more proper solution but all I can think of is just turning the dot product into an angle and making two new CFrames that point away using that angle.

Based on the picture, I’m guessing you want lines? See the comments below for an explanation of what’s happening but you’re probably looking for something like this:

Code

local function getSegmentsFromOrigin(cframe, dotFovRange, fovLength, rotationAxis)
-- the axis we'll rotate around (relative to the local space of the cframe)
rotationAxis = rotationAxis or Vector3.yAxis
-- clamp the fov dot product to ensure it's normalised
dotFovRange = dotFovRange or 0.3
dotFovRange = math.clamp(dotFovRange, -1, 1)
-- clamp line length to positive number
fovLength = math.max(fovLength or 1, 0)*0.5
-- compute the angle from the dot product
local theta = math.acos(dotFovRange)
-- compute the first line's origin (offset by the line length)
local lineA = cframe * CFrame.fromAxisAngle(rotationAxis, theta)
lineA += lineA.LookVector*fovLength
-- compute the second line's origin by negating the angle (offset by the line length)
local lineB = cframe * CFrame.fromAxisAngle(rotationAxis, -theta)
lineB += lineB.LookVector*fovLength
return lineA, lineB
end

Usage

-- e.g. to use the method below...
local cframe = workspace.some.part.CFrame -- the turret origin
local fovRange = 0.3 -- the dot product you measured earlier
local fovLength = 10 -- i.e. the far plane z (or, the maximum distance of each line)
local rotationAxis = Vector3.yAxis -- the axis on which to rotate (defaults to the yAxis)
local cframeLineA, cframeLineB = getSegmentsFromOrigin(cframe, fovRange, fovLength, rotationAxis)
-- apply to the parts ...
partLineA.CFrame = cframeLineA
partLineBCFrame = cframeLineB

Thank you, what ive been consistently running into is the issue of the lines not facing the way the character is facing. Like not being relative to their look vector?, I have tried multiplying the character look vector and the parameter cframe but then it just seems to be placed in the same position all the time. The angled zone seems to be completely correct, is this a cframe.angles thing?

I hope im not asking for too much, just this angle logic has been very hard to implement for a while now.

Sorry for the late reply I have been working. But a fresh mind did make me realise that my CFrame parameter was a position converted to a CFrame, hence no angles. Thank you very much for your help