# Having trouble making sight "triangular" (?)

You can write your topic however you want, but you need to answer these questions:

1. What do you want to achieve? Keep it simple and clear!
I want to add sight to my AI like the picture shown below ( The “sight” is the triangle ) :

2. What is the issue? Include screenshots / videos if possible!
It sometimes make the weirdly shaped triangle(?) :

3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I had tried my own solution ( Somehow my brain make the worst ideas on trying find the solution only ), had also tried looking to DevForum.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

I ain’t going to give you the full script but yeah, I going to just give you some parts of the script

Variables :

``````local FieldOfView, SightDistance = 25, 50
local ReflexTime, Points = 1, 0
``````

The code that make those “triangle” :

``````local function ShowSight(ray)
local MidPoint = ray.Origin + ray.Direction/2

local Part = Instance.new("Part", workspace)
Part.Anchored = true
Part.CanCollide = false
Part.Size = Vector3.new(.25, .25, ray.Direction.Magnitude)
Part.CFrame = CFrame.lookAt(MidPoint, ray.Origin)

return Part
end

local function MakeView()
local CalculatedMath = (SightDistance / (Points+1 / 10) * 200 * ((Points * ReflexTime) / 350000 + ReflexTime/300000))
for x = -FieldOfView, FieldOfView, FieldOfView * CalculatedMath / 10 do
local CalculatedCFrame =  CFrame.new(Character.PrimaryPart.CFrame.LookVector * SightDistance) * (CFrame.new(Character.PrimaryPart.CFrame.LookVector) * CFrame.new(x,0,0))
local ray = Ray.new(Character.PrimaryPart.Position, CalculatedCFrame.Position)
ShowSight(ray)
end
end

while true do
WanderAround()
MakeView()

task.wait(ReflexTime * 5) -- I mutliplied it by 5 for debugging or something like that
end
``````

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Please tell me if this topic is in the wrong category since I really need to find solution to this problem.

I think you have the CFrame of the far line in world space, not object space.
If you look at the line that’s drawn by the far edge of the triangle it’s in line with the base grid squares.
Object and World Space | Roblox Creator Documentation

1 Like

Alright, I done some changes on the script but I can’t seem to make the “triangle” to the front vector of the PrimaryPart/Head of the character, here what I mean :

See what I meant? the “triangle” doesn’t go to the front vector of the part that I said before.

Also here’s the code

``````local function MakeView()
local CalculatedMath = (SightDistance / (Points+1 / 10) * 200 * ((Points * ReflexTime) / 350000 + ReflexTime/300000))
if CalculatedMath < .125 then CalculatedMath = .125 end

for x = -FieldOfView, FieldOfView, FieldOfView * CalculatedMath / 10 do
local CalculatedCFrame = (Character:GetPivot() * CFrame.new(0,0,SightDistance)) * CFrame.new(x,0,0)
local FinishedCFrame =  CalculatedCFrame:ToObjectSpace(Character:GetPivot())
local ray = Ray.new(Character:GetPivot().Position, FinishedCFrame.Position)
ShowSight(ray)

end
end
``````

Sorry for late response, I had stuffs to do. And also sorry if I make any grammars mistakes.

Update 1 : I have made it to the front vector of the PrimaryPart/Head of the character, BUT there’s one problem… I should probably show you what’s the problem, so here’s it is :

I want it to look like this :

See the problem there? The sight has a weird “shape” (?)
Anyways, here is the new code that I recently changed :

``````local function MakeView()
local CalculatedMath = (SightDistance / (Points+1 / 10) * 200 * ((Points * ReflexTime) / 350000 + ReflexTime/300000))
print(CalculatedMath, "Hi "..FieldOfView * CalculatedMath / 10)
-- Ignore the thing above this text, please

if CalculatedMath < .125 then CalculatedMath = .125 end

for x = -FieldOfView, FieldOfView, FieldOfView * CalculatedMath / 10 do
local LookVector = Character:GetPivot().LookVector
local CalculatedCFrame = Character:GetPivot() * CFrame.new(LookVector * SightDistance, (LookVector * SightDistance) * Vector3.new(LookVector.X - x,0,0) )
local FinalCFrame =  CalculatedCFrame:ToObjectSpace(Character:GetPivot())
--local CalculatedVector = Character:GetPivot().LookVector * (SightDistance * x)
--local FinalCFrame = CFrame.new(CalculatedVector):ToObjectSpace(Character:GetPivot())
local ray = Ray.new(Character:GetPivot().Position, FinalCFrame.Position)
ShowSight(ray)

end
end
``````

Update 2 : I edited this topic’s name because it’s doesn’t fit on the problem that I am facing right now.
Edit : Putting another picture or something like that idk.

I’m not really sure about CFraming, but from ALL your pictures the line that the Humanoid’s Pivot points to is ending up in line with the baseplate grid.
The line I posted above seems to be CFraming the angle to a Position, not an Orientation.

Yo, already got the solution to my problems. Thanks you so much on helping me, and also If someone ever wanted the code, here’s it :

``````local function MakeView()
local CalculatedMath = (SightDistance / (Points+1 / 10) * 200 * ((Points * ReflexTime) / 350000 + ReflexTime/300000))
print(CalculatedMath, "Hi "..FieldOfView * CalculatedMath / 10)

if CalculatedMath < .125 then CalculatedMath = .125 end

for x = -FieldOfView, FieldOfView, FieldOfView * CalculatedMath / 10 do
-- The CalculatedCFrame one.
local CalculatedCFrame = CFrame.Angles(0,math.rad(x),0):ToObjectSpace(CFrame.new(Character:GetPivot().LookVector * SightDistance))
local ray = Ray.new(Character:GetPivot().Position, CalculatedCFrame.Position)
ShowSight(ray)