#Help with sorting out a "Vision cone system"

1 messages · Page 1 of 1 (latest)

strange mason
#

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

fervent sentinel
#

that should be enough

strange mason
#

Alright, where should i input the rootpart rotation?

fervent sentinel
strange mason
#

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

fervent sentinel
#

i'm not sure of how you create the cone yet

strange mason
#

Its using the script above

fervent sentinel
#

it's made out of two wedges?

strange mason
#

No multiple wedges

#

it raycasts out from the player and creates multiple wedges

strange mason
#

Here is a video demonstrating the issue

white ledge
#

i remember doing this a long time ago in scratch

#

but it was a shadow thing

strange mason
#

Oh yeah?

#

How did you do that if you dont mind me asking?

fervent sentinel
#

then just make sure the pivot point is at the rootpart and rotate the model

white ledge
#

and everything behind the collision was black

#

everything that wasn't behind the collision was white

#

(white was light)

#

the light source was mouse

#

was pretty shitty tho