#Help with sorting out a "Vision cone system"
1 messages · Page 1 of 1 (latest)
Currently my script which is shown here:
wedge.Anchored = true
wedge.TopSurface = Enum.SurfaceType.Smooth
wedge.BottomSurface = Enum.SurfaceType.Smooth
local function draw3dTriangle(a, b, c, parent, w1, w2)
local ab, ac, bc = b - a, c - a, c - b
local abd, acd, bcd = ab:Dot(ab), ac:Dot(ac), bc:Dot(bc)
if abd > acd and abd > bcd then
c, a = a, c
elseif acd > bcd and acd > abd then
a, b = b, a
end
ab, ac, bc = b - a, c - a, c - b
local right = ac:Cross(ab).unit
local up = bc:Cross(right).unit
local back = bc.unit
local height = math.abs(ab:Dot(up))
w1 = w1 or wedge:Clone()
w1.Size = Vector3.new(math.min, height, math.abs(ab:Dot(back)))
w1.CFrame = CFrame.fromMatrix((a + b) / 2, right, up, back)
w1.Color = Color3.new(1, 1, 1)
w1.Transparency = .95
w1.Parent = parent
w1.CanCollide = false
w1.Anchored = true
w1.CastShadow = false
w2 = w2 or wedge:Clone()
w2.Size = Vector3.new(math.min, height, math.abs(ac:Dot(back)))
w2.CFrame = CFrame.fromMatrix((a + c) / 2, -right, up, -back)
w2.Color = Color3.new(1, 1, 1)
w2.Transparency = .95
w2.Parent = parent
w2.CastShadow = false
w2.CanCollide = false
w2.Anchored = true
return w1, w2
end```
local RaycastParams = RaycastParams.new()
RaycastParams.FilterType = Enum.RaycastFilterType.Exclude
RaycastParams.FilterDescendantsInstances = {wedge, tower, game.Players.LocalPlayer.Character, hideables}
return workspace:Raycast(center, direction, RaycastParams)
end
local Circle = nil
local lastVertices = {}
local function CreateCircle(center, radius, numSegments, parent)
local vertices = {}
local startAngle = math.rad(-55)
local endAngle = math.rad(55)
local step = (endAngle - startAngle) / numSegments
for i = 0, numSegments - 1 do
local angle = startAngle + step * i
local x = center.x + radius * math.cos(angle)
local z = center.z + radius * math.sin(angle)
local vertex = Vector3.new(x, center.y, z)
local hit = RaycastFromCenter(center, (vertex - center).unit * (vertex - center).magnitude)
table.insert(vertices, hit and hit.Position or vertex)
end
local positionsChanged = false
if #lastVertices == #vertices then
for i = 1, #vertices do
if (vertices[i] - lastVertices[i]).magnitude > 0.01 then
positionsChanged = true
break
end
end
else
positionsChanged = true
end
if positionsChanged then
if Circle then
Circle:Destroy()
end
Circle = Instance.new("Model")
Circle.Parent = parent
for i = 1, #vertices - 1 do
if vertices[i] and vertices[i + 1] then
local w1, w2 = draw3dTriangle(vertices[i], vertices[i + 1], center, Circle)
w1.Parent = Circle
w2.Parent = Circle
end
end
lastVertices = vertices
end
end```
Currently, the cone will be projected out just infront of the player
always in the same direction
How can I make the cone will be in the lookvector or the position the player is facing?
This is then called in RenderStepped underneath
local numSegments = 20
local centerPosition = tower.PrimaryPart.Position
CreateCircle(centerPosition, radius, numSegments, tower)```
Im unsure as where to fit in the position and direction that the player is actually looking at
i guess you can get the rootpart rotation
that should be enough
Alright, where should i input the rootpart rotation?
what are you trying to create anyway? not to stop you from creating more advanced scripts and learn from them, but you might be over complicating something
Well
I paid for a commision
I demonstrated what i wanted
They said yues
They gave me something that i didnt ask for
i asked them to alter it to what i asked for
they said no and took the robux
Heree is a better example of what i mean
This image here showcases what the player can see inside their vision cone
which is what that script showcases
However
I asked for it to not just face right, but for the cone to face the direction that the player faces
For example, here i turn my character to look another way however the cone does not move with it
the arrow indicating the direction i am facing
the easiest solution would be to set the pivot point in code to the rootpart and rotate the cone
i'm not sure of how you create the cone yet
Its using the script above
^
it's made out of two wedges?
ah i see now but in the end they're all parented to the main model right?
then just make sure the pivot point is at the rootpart and rotate the model