Raycast in a sphere?

I took a look at this post and created a circular raycast:

This is my code:

![image|484x174](upload://9b4ODKc22lzwHXLZfLSW87WxtE4.png)

And I currently get this:
image

But I need to make it 3d (a sphere), and I have no clue how to

IGNORE THERE BEING NO RAYCAST, I WILL READD THAT AFTER IT BECOMES A SPHERE

Edit: Spherecast will not work since I need multiple rays and not one raycast.

3 Likes

workspace:Spherecast()

This was added not that long ago (At least as of writing this), which makes the topic you’re viewing outdated, it should also simplify that process for you.

1 Like

Spherecast will not cut it since it does not look like it fires off multiple rays. I probably should clarify that this is for a light baking plugin.

Hey there! I am actually the original author of that post, while the original thread is for cylinder shapes, it’s luckily pretty easy to convert to a sphere.

Really all you need is the y axis (as well as a theta angle) to convert the pre-existing code, which can be calculated using the following line

for theta = 0, 180 do
   local y = r * math.cos(math.rad(theta))
end
1 Like

EDIT: I fixed it, I just added the original Y value as “l”

local center = cframe.Position
	local h,l,k = center.X,center.Y,center.Z
	
	if light:IsA("PointLight") then
		for i=1,360,numSamples do
			local rad = math.rad(i)
			local x = h+radius*math.cos(rad)
			local z = k+radius*math.sin(rad)
			
			for t=0,360,numSamples do
				local y = l+radius*math.cos(math.rad(t))
					
				local n = Vector3.new(x,y,z)

				DrawLine(center,n,(center-n).Magnitude,folder)
			end
		end
	end

Do you know how I could make it so that the higher the number of samples, the higher the amount of rays rather than the lower number of samples, the higher amount of rays?

EDIT (again): 360/numSamples

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