6 Vertices instead of 8

I put the numbers by offset, it seems correct, but there are 2 vertices located in the same place as the other 2, so there are 6 vertices (need to be 8), why?


for j = 1, 8 do
					    local offsetX = (j % 2 == 0) and 0.5 or -0.5
						local offsetY = ((j > 4) and -0.5 or 0.5)
						local offsetZ = ((j > 2 and j < 5) and 0.5 or -0.5)
						vertices[j] = pos + Vector3.new(size.X * offsetX, size.Y * offsetY, size.Z * offsetZ)
					end
					local ViewportSize = Camera.ViewportSize
					local AspectRatio = ViewportSize.X/ViewportSize.Y

					local VerticalFoV = math.rad(Camera.FieldOfView)

					local ScreenSizeY = 2*math.tan(VerticalFoV/2)
					local ScreenSizeX = AspectRatio*ScreenSizeY
					
					local RelativePosition1 = Camera.CFrame:Inverse() * vertices[i]

					local ScreenPositionX1 = RelativePosition1.X/-RelativePosition1.Z
					local ScreenPositionY1 = RelativePosition1.Y/-RelativePosition1.Z

					frame.Position = UDim2.fromScale(
						1/2 + ScreenPositionX1/ScreenSizeX,
						1/2 - ScreenPositionY1/ScreenSizeY
					)

do 10 verticles then
since 8-2 = 6 so 10-2 = 8

8 vertices appear, it’s just that two of them are in the same place as another
two

somethings with your code then
and send it fully but i dont know how to script these types of coed but for those who wants to fix this would probably know a bit

local Map = workspace:WaitForChild("Map"):GetDescendants()
local Camera = workspace.CurrentCamera
local CanvasModule = require(script.Parent.CanvasDraw)
local Canvas = CanvasModule.new(script.Parent.Parent.Frame, Vector2.new(150,150))
local brickTexture = CanvasModule.GetImageData(game.ReplicatedStorage.Textures.RedCube) 
local a = 0

for _, Object in pairs(Map) do
	if Object:IsA("BasePart") then
		for i = 1, 8 do
			a += 1
			local folder = script.Parent.Parent.Frames
			local frame = Instance.new("Frame")
			frame.Parent = folder
			frame.AnchorPoint = Vector2.new(0.5, 0.5)
			frame.BackgroundColor3 = Color3.new(0,1,0)
			frame.Name = "Frame".. a
			frame.Size = UDim2.new(0,10,0,10)
			

			coroutine.wrap(function()
				while true do
					local vertices = {} 
					local pos = Object.Position
					local size = Object.Size
					for j = 1, 10 do
					    local offsetX = (j % 2 == 0) and 0.5 or -0.5
						local offsetY = ((j > 6) and -0.5 or 0.5)
						local offsetZ = ((j > 2 and j < 5) and 0.5 or -0.5)
						vertices[j] = pos + Vector3.new(size.X * offsetX, size.Y * offsetY, size.Z * offsetZ)
					end
					local ViewportSize = Camera.ViewportSize
					local AspectRatio = ViewportSize.X/ViewportSize.Y

					local VerticalFoV = math.rad(Camera.FieldOfView)

					local ScreenSizeY = 2*math.tan(VerticalFoV/2)
					local ScreenSizeX = AspectRatio*ScreenSizeY
					
					local RelativePosition1 = Camera.CFrame:Inverse() * vertices[i]

					local ScreenPositionX1 = RelativePosition1.X/-RelativePosition1.Z
					local ScreenPositionY1 = RelativePosition1.Y/-RelativePosition1.Z

					frame.Position = UDim2.fromScale(
						1/2 + ScreenPositionX1/ScreenSizeX,
						1/2 - ScreenPositionY1/ScreenSizeY
					)
					
					local visibleSides = {}

					for j = 1, 6 do
						local normal = (vertices[j + 1] - vertices[j]):Cross(vertices[j + 2] - vertices[j]).Unit
						local toCamera = Camera.CFrame.Position - vertices[j]
						if normal:Dot(toCamera) > 0 then
							table.insert(visibleSides, j)
						end
					end

					local function frame(name)
						return Vector2.new(folder:WaitForChild(name).Position.X.Scale, folder:WaitForChild(name).Position.Y.Scale) * 150
					end

					local function drawTriangle(num1, num2, num3, Color)
						Canvas:DrawTriangle(frame("Frame" .. num1), frame("Frame" .. num2), frame("Frame" .. num3), Color, true)
					end

					for _, sideIndex in ipairs(visibleSides) do
						if sideIndex == 1 then
							drawTriangle(1, 2, 3, Color3.new(1, 1, 0))
							drawTriangle(2, 3, 4, Color3.new(1, 1, 0))

						elseif sideIndex == 2 then
							drawTriangle(2, 4, 8, Color3.new(0, 1, 0))
							drawTriangle(8, 4, 7, Color3.new(0, 1, 0))

						elseif sideIndex == 3 then
							drawTriangle(5, 7, 8, Color3.new(0, 0, 1))
							drawTriangle(5, 6, 7, Color3.new(0, 0, 1))

						elseif sideIndex == 4 then
							drawTriangle(1,6,5, Color3.new(0,1,1))
							drawTriangle(1,6,3, Color3.new(0,1,1))
						elseif sideIndex == 5 then
							drawTriangle(1,5,8, Color3.new(1, 0, 0))
							drawTriangle(1,8,2, Color3.new(1, 0, 0))
						elseif sideIndex == 6 then
							continue 
						end
					end

					task.wait()
					
					Canvas:Clear()
				end
			end) ()
		end
	end
end

fixed (ignore////////////////////)

we solved:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.