I’m currently working on a view cone system for my game enemies. I’m having trouble calculating the X and Y position of each ray cast target point. I’ve tried multiple equations but almost always end up with a circle of parts around the origin.
The code should take an origin part, a radius, and an angle. It should generate a set amount of ray target positions within the angle from the part’s look vector. My most recent code looks like this:
local radius = 30
local angle = 30
local rayCount = angle/2
for i = 1,rayCount,1 do
local angle = i * (((math.pi * radius * angle) / 180) / rayCount)
local x = orininPart.Position.X + (radius * math.cos(angle))
local z = orininPart.Position.Z + (radius * math.sin(angle))
local targetPosition: Vector3 = (Vector3.new(x,0,z))
--local targetPosition: Vector3 = (orininPart.CFrame * CFrame.new(x,0,y)).Position
--local raycast = workspace:Raycast(orininPart.Position,(targetPosition - orininPart.Position).Unit * radius,castData.rayParams or RAY_PARAMS)
--visualizeCast(raycast,orininPart.Position,targetPosition)
Utility:CreateObject("Part",{
Color = Color3.fromRGB(255, 0, 0),
Anchored = true,
CanCollide = false,
CanQuery = false,
CanTouch = false,
CastShadow = false,
Material = Enum.Material.Neon,
Size = Vector3.new(1,1,1),
Position = targetPosition,
Parent = workspace
})
end
Right now I’m simply making a part at the position for proof of concept. An amazing drawing of the ideal result:
If any math people have a solution that would be awesome, thanks.