Raycasting a Circle with numbers from -10 to 10 on the x and y axis?

So, I want to make a laser projector, currently i’m trying to figure out how to make figures like a circle, I do have a module that I made yesterday (yes its very bad I was lazy):


local BeamsFolder = script.Parent:WaitForChild("Beams")
local CasterPart = script.Parent:WaitForChild("Caster")
local SpotLight0 = CasterPart.SpotLight0
local Spotlight1 = CasterPart.SpotLight1

local Projector = {}

function Projector.newBeamToPoint(xStuds: number, yStuds: number, color: Color3, MaxDistance: number)	
	if xStuds and yStuds and color and MaxDistance then
		
		local x2 = math.clamp(xStuds, -10, 10)
		local y2 = math.clamp(yStuds, -10, 10)
		local position = Vector3.new(0, 0, CasterPart.Position.Z)
		
		local raycastParams = RaycastParams.new()
		raycastParams.IgnoreWater = true
		raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
		raycastParams.FilterDescendantsInstances = {BeamsFolder}
		local result = workspace:Raycast(CasterPart.Position, CasterPart.CFrame.LookVector * MaxDistance, raycastParams)
		if result then position = Vector3.new(position.X, position.Y, result.Position.Z) else position = Vector3.new(position.X, position.Y, (CasterPart.CFrame.LookVector * MaxDistance)) end
		
		if x2 < 0 then
			position = Vector3.new((CasterPart.Position.X - -x2), position.Y, position.Z)
		elseif x2 > 0 then
			position = Vector3.new((CasterPart.Position.X + x2), position.Y, position.Z)
		elseif x2 == 0 then
			position = Vector3.new(CasterPart.Position.X, position.Y, position.Z)
		end
		if y2 < 0 then
			position = Vector3.new(position.X, (CasterPart.Position.Y - -y2), position.Z)
		elseif y2 > 0 then
			position = Vector3.new(position.X, (CasterPart.Position.Y + y2), position.Z)
		elseif y2 == 0 then
			position = Vector3.new(position.X, CasterPart.Position.Y, position.Z)
		end
		
		SpotLight0.Color = color
		Spotlight1.Color = color
		SpotLight0.Enabled = true
		Spotlight1.Enabled = true
		
		print(position)
		
		local result2 = workspace:Raycast(CasterPart.Position, position, raycastParams)
		if result2 then
			local midPoint = CasterPart.Position + position/2
			
			local Beam = Instance.new("Part")
			Beam.Material = Enum.Material.Neon
			Beam.Anchored = true
			Beam.CanCollide = false
			Beam.Color = color
			Beam.CanTouch = false
			Beam.CFrame = CFrame.new(midPoint, CasterPart.Position)
			Beam.Size = Vector3.new(.01, .01, position.Magnitude)
			Beam.Parent = BeamsFolder
			
			return Beam
		end
		
	end
end

function Projector.Clear()
	BeamsFolder:ClearAllChildren()
end

return Projector

So that, uses numbers from -10 to 10 on the X and Y axis, and I want to make a circle with that. But how?


local random = Random.new(tick())

local projectorModule = require(workspace.LaserProjector.Projector)

local times = 0
while task.wait() do
	times += 1
	
	if times >= 50 then
		projectorModule.Clear()
		times = 0
	end
	
	projectorModule.newBeamToPoint(random:NextNumber(-10, 10), random:NextNumber(-10, 10), Color3.new(random:NextNumber(), random:NextNumber(), random:NextNumber()), 500)
end

^ that currently just puts beams in random positions:

and I want it to make patterns, like that circle I drew on the image. (I’m making a laser projector, tried to make reflecting rays at first but uhhh, yeah that wouldn’t work.)

a position on a circle is Vector2.new(math.cos(X),math.sin(X))*Radius.
If you run this in a for loop, it should get the positions on a circle.

1 Like

Can you explain? I’m not really a math guy. Also what is the X variable in the math.cos and math.sin?

And what should I put in the for loop to use that meth?

Hmm, something:

X is simply just a variable. it can be any number you want.
The sin returns a Y in the unit circle, which is a circle with the radius of 1. Making an angle of 1rad = to a distance of pi on the circle
The cosine is almost the same. It returns the X value on the circle (not the same as the earlier X)
This means that sin(X+.5*pi) = cos(X).

Here’s the sine and cosine in a gif:
image

the fu-

ah, i see, the wave thingys rotate in a way that it makes a circle

first of all, don’t do meth.
Secondly, it can look something like this:

for X = i,math.pi*100 do
local Pos = Vector2.new(math.cos(X/100),math.sin(X/100))
print(Pos)
end

This will return a set of points on a circle with a radius of 1

2 Likes

Wow, you are smart, i’m gonna try to look how this works.

i made a nice place for this a while ago that makes points on the ground. imma see if i can find it


no bottom


local random = Random.new(tick())

local projectorModule = require(workspace.LaserProjector.Projector)

while true do
	for X = 1, math.pi*100 do
		projectorModule.Clear()
		local Pos = Vector2.new(math.cos(X/100),math.sin(X/100))*10
		projectorModule.newBeamToPoint(Pos.X, Pos.Y, Color3.new(random:NextNumber(), random:NextNumber(), random:NextNumber()), 500)
		task.wait()
	end
end

made a little mistake on my part, sorry.
It should go from 0 to 2pi.
pi = 180 deg
2pi = 360 deg

Here’s the place btw
CirclePlace.rbxl (2.3 MB)