Editable Mesh backface detection

Hello everyone, I want to make a system so that the polygon always turns towards the player’s camera. This is done to ensure that both sides of the model have the same shading, which is not achieved with DoubleSided.

How can you detect that a player is looking at the back of the polygon? of all the information, there is only this:

image

1 Like

ChatGPT can explain it better than i can so i’ll just share the conversation.

here is the refined code and a place file of a working version.
PlaceFile.rbxl (57.5 KB)

local camera = workspace.CurrentCamera

local p1 = workspace:WaitForChild("P1").Position
local p2 = workspace:WaitForChild("P2").Position
local p3 = workspace:WaitForChild("P3").Position


local function getTrianglePlane(p1, p2, p3)
	local v1 = p2 - p1
	local v2 = p3 - p1
	local normal = v1:Cross(v2)  -- (A, B, C)
	local D = -normal:Dot(p1)  -- Compute D
	return normal, D
end

local function pointPlaneSide(normal, D, point)
	local distance = normal:Dot(point) + D
	return distance
end

game:GetService("RunService").Heartbeat:Connect(function()
	local cameraPosition = camera.CFrame.Position

	local normal, D = getTrianglePlane(p1, p2, p3)
	local side = pointPlaneSide(normal, D, cameraPosition)

	if side > 0 then
		print("front side")
	elseif side < 0 then
		print("back side")
	else
		print("on the triangle's plane.")
	end
end)
1 Like

This stops working with Editable Mesh triangles, but it works, but incorrectly