How to make raycasting go on a certain shape

Basically, I’m making a LiDAR game, and I figured how to make raycasting at random in the area around the cursor. (Spread) the random is as follows:

RunService.RenderStepped:Connect(function()
	if cooldown == false then
		local randomV = Random.new(math.random(1,1000))
		
		local rayParams = RaycastParams.new()
		rayParams.FilterType = Enum.RaycastFilterType.Blacklist

		local tableRay = {

		}

		for i,part in pairs(localPlayer.Character:GetDescendants()) do
			if part:IsA("BasePart") and not table.find(tableRay,part) then
				table.insert(tableRay,part)
			end
		end
		for i,part in pairs(localPlayer.Character.Humanoid:GetAccessories()) do
			if not table.find(tableRay,part) then
				table.insert(tableRay,part)
			end
		end

		rayParams.FilterDescendantsInstances = tableRay
		
		
		local Spread = 5
		local offset = Vector3.new(randomV:NextInteger(-Spread,Spread),randomV:NextInteger(-Spread,Spread),randomV:NextInteger(-Spread,Spread))
		
		local newPos = currentCamera.CFrame.Position + offset

		local rayLidar = workspace:Raycast(newPos,currentCamera.CFrame.LookVector * 100000,rayParams)
		print(rayLidar)
		if rayLidar ~= nil and rayLidar.Instance.Parent ~= workspace.rayParts then
			print(rayLidar.Instance)
			print(rayLidar.Position)
			local clonedPart = ReplicatedStorage.samplePart:Clone()
			clonedPart.CFrame = CFrame.lookAt(rayLidar.Position,rayLidar.Position - rayLidar.Normal)
			clonedPart.Parent = workspace.rayParts
			workspace.graphicBeep:Play()
			task.wait(0.01)
		end
	end
end)

How would I alter this so that it raycasts in a shape, like a square for example?

1 Like

bump, need help on how to do this

Hey, you cannot bend rays, if this is only cosmetic you should use parts instead.

hey, probably should’ve clarified. So, one raycast sends out this sample part and makes one little dot. Multiple dots can be done with multiple raycasts. the code I put in above does a lot of raycasts so it paints the terrain around you very well. though it’s at random and still a bit slow for what I’m trying to do.

I’m trying to make a whole square-shaped wall of those dots. I’m just not sure how to change the randomization part of the code and fit it to one size that goes by where the character is looking.

Are you able to provide me a screenshot of what it does?

So, in the screenshot below, this is what happens when you hold F for 2-3 seconds



As you can see, the dots are all scattered because they’re randomized. What I’m going for is a full square of these dots in the area the camera is looking at, as it would help the visualization and comprehension of the environment and increase speed of scan. A square that would of course differ in depth depending on your area.

1 Like

Soo, instead of them being randomly placed, you want them in a pattern?

pretty much, in certain shapes. I’m just not sure how to approach this.

1 Like

bump, still need help on this problem

1 Like