How to make nightclub lasers?

I want to make nightclub type lasers, as in they start at one place but end on another and are constantly moving. something like this: https://www.laserworld.com/images/stories/2016/Opera-Club-Zagreb-02/Laserworld_at_Opera_Club_Zagreb_by_Luminos-0005-web.jpg I cant just rotate it normally because one end needs to be fixed at a certain place but the other end is always moving. How would I do this?

4 Likes

Rotate a part, beam or whatever about a position but constrain the rotation in 3D. Not sure, but spherical coordinates might be useful and it’s fairly wasy to derive spherical coordinates from cartesian coordinates.

I thought it would be an interesting challenge to program a constrainable figure-eight pattern, to create this sort of visual effect.

Here’s a demonstration of what I settled on:

local RunService = game:GetService("RunService")

local rotator = script.Parent
local origin = rotator.CFrame

local dampener = 5 -- higher numbers result in lower speed
local maxRotation = 180
local x,y = 0,0

local lerp = function (a, b, t)
	return (1-t)*a + t*b
end

RunService.Heartbeat:connect(function(dt)
	local t = (tick()/dampener)%2
	x,y = lerp(-1,1,t),lerp(1,-1,t)
	rotator.CFrame = origin*CFrame.Angles(math.rad(x*maxRotation),math.rad(y*maxRotation),0)
end)

This effect could probably be achieved in a simpler way, but this works.
One silly part of this math that I would spend time to correct is that the maxRotation must be set to a multiple of 90.

If you want a crazy fast random blinky laser, lower the dampener and raise the maxRotation to a ridiculously high value.

Here’s the file:
Nightclub Laser.rbxm (4.5 KB)

3 Likes

beams can come in handy. The lighting community on roblox is absolutely incredible, being apart of it I can safely say that the work and fixtures we’ve made have had a positive impact on the communities

What is the “lighting community” on Roblox? Do you publish resources for other developers somewhere?

And yes, if you wanted to, you could easily replace the welded Part I’m using with a Beam.

Further optimizations would include drawing a Ray from the lookVector of the origin until it contacts an object, and then constrain the size of the beam so that it does not penetrate walls.

My example code is not that extensive because it was only the pattern of rotation that I was interested in achieving.

Thank you so much! this was more than I was asking for!

1 Like