Laser dot pointer

how can i make a laser pointer making dot, that collide on object?
like this


3 Likes

For the lasers you could use ray casting which is an easy method to make a laser

3 Likes

For this you could either use a loop and cast a ray repeatedly and use a part thats size is the same as the rays magnitude, or you could use a beam and set the attachments position to either the mouse or a ray.

3 Likes

Let’s say that you have a laser pointer emitter, i.e from where the laser will emit then you will use workspace:Raycast() to cast a ray.

Assuming that the front of the part is where you want the pointer to go. So:

local originPart = -- OriginPart
local endAttachment = -- The end attachment for the beam.
local distance = 2048 -- How far the laser can go. Don't use math.huge as it can break the raycasts.
local Params = RaycastParams.new()
Params.FilterDescendentInstances = {Gun}

local function RecalculatePosition()
   local ray = workspace:Raycast(originPart.Position,originPart.CFrame.LookVector*distance,Params)
   local endPosition = ray and ray.Position or 
   originPart.Position+originPart.CFrame.LookVector*distance
   endAttachment.WorldPosition = endPosition
end

originPart.Changed:Connect(RecalculatePosition)
2 Likes

i found tutorial to raycasting and my script worked, but when i move dot subject like wall, dot doesn’t move forward.
robloxapp-20240319-1618389.wmv (817.9 KB)

	local param = RaycastParams.new()
	local att1 = script.Parent.Attachment
	local att2 = script.Parent.Attachment1

	while true do
		wait()
	local ray = game.Workspace:Raycast(script.Parent.Position, att2.CFrame.LookVector*15000, param)
	if ray then
		att2.Position = ray.Position - script.Parent.Position
	end
	end
1 Like
local param = RaycastParams.new()
local att1 = script.Parent.Attachment
local att2 = script.Parent.Attachment1

while true do
	wait()
	local ray = game.Workspace:Raycast(script.Parent.Position, att2.CFrame.LookVector*15000, param)
	if ray then
		att2.Position = ray.Position - script.Parent.Position
	else
		att2.Position = att2.CFrame.LookVector*15000
	end
end
2 Likes

Thank you very much, it worked!

1 Like

No problem! If you have any other issue you can always ask me.

1 Like

For some reason I read the title Laser dot PRINTER. I need coffee.

2 Likes

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