I know i can use these codes to make circle detect.
local center = Vector3.new(0,0,0) -- Center of area local radius = 80 while wait() do if (center-games.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude <= radius then print("Player is inside area") end end
But how about sector detect?
I'm not really want use touch detect,But if this is the only answer,I'll take that.
Thanks for answering!
This is down to rather simple vector math. You can find a step-by-step guide from an answer to a very similar stackoverflow question. Here's an example on how it can be implemented on Roblox:
local function areClockwise(v1, v2) v1, v2 = Vector2.new(v1.X, v1.Z), Vector2.new(v2.X, v2.Z) return v1:Cross(v2) > 0 end local function isWithinRadius(point, radius) return Vector2.new(point.X, point.Z).Magnitude <= radius end local function isInsideSector(point, origin, sectorStart, sectorEnd, radius) return not areClockwise(sectorStart, point) and areClockwise(sectorEnd, point) and isWithinRadius(point, radius) end -- local origin = workspace.origin.Position local startPoint, endPoint = workspace.point1, workspace.point2 -- You most likely have a known radius and thus this should be unnecessary local startVector, endVector = (startPoint.Position - origin), (endPoint.Position - origin) local radius = (startVector.Magnitude + endVector.Magnitude) / 2 -- local player = game.Players.PlayerAdded:Wait() local character = player.CharacterAdded:Wait() local primaryPart = character.PrimaryPart game:GetService("RunService").Heartbeat:Connect(function() local point = (primaryPart.Position - origin) local isInside = isInsideSector(point, origin, startPoint.Position - origin, endPoint.Position - origin, radius) local brickColor = isInside and BrickColor.Green() or BrickColor.Red() startPoint.BrickColor, endPoint.BrickColor = brickColor, brickColor end)
There are certain limitations mentioned in the SO answer.
EDIT: Fixed the link to point to the actual answer
Though you do not want to use touch detect, it is indeed recommended and much much easier.