How can I make these beams line up effectively?

Hey! I’m trying to make these conveyors that can be placed by the user and it has a beam with attachments that make a moving animation (eg:)
image

But when you I multiple up, sometimes the beams glitch at the ends of the conveyors and it’s very mildly infuriating to me. It does get worse than that but it just goes away too fast to get a high enough quality screenshot and I don’t know how to record my screen on this laptop lmao

I don’t really know where to start with trying to line them up effectively, I wanted to do a magnitude check for the beginnings and endings of each conveyor and then link the beginning beam and whatever but my brain hurts trying to write that code.

I got here and then basically had a stroke and decided to make this post:

local getNearest = function(con,list)
	local lim = 0.25;
	local linked = {};
	for _,conveyor in pairs(list) do
		if(conveyor ~= con) then
			local endPart = (con.Start.Position - conveyor.End.Position).magnitude;
			local startPart = (con.End.Position - conveyor.Start.Position).magnitude;
			if(endPart <= lim or startPart <= lim) then
				linked[conveyor] = true;
			end
		end
	end
	print(linked)
end

local linkBeams = function(conveyor)
	local objects = conveyor.Parent:GetChildren();
	local linked = conveyor:GetAttribute("LinkedModule"); -- ignore this, basically makes sure it's actually a conveyor lol
	local total = {};
	for _,object in pairs(objects) do
		if(object:GetAttribute("LinkedModule") == linked) then
			table.insert(total,object);
		end
	end
	if(#total >= 1) then
		for _,con in pairs(total) do
			local nearest = getNearest(con,total)
		end
	end
end

Does anyone have any posts similar to this one? I couldn’t find any because it’s so oddly specific, and if there’s a better solution to my problem please tell me. I just don’t know what to do from here.

Beams have a function called :SetTextureOffset() that allows you to set the beam’s current offset, or “progress” of their movement.

Not sure if this would work, but you could go through all your beams with a for loop to use :SetTextureOffset() on all of them at the same time, which should make them “sync” and fix your problem.

I did end up doing this, I hope there’s not severe performance implications on it’s behalf though. In preparation of that I’m going to utilize the following:

  • Determine if the player can actually see the object (if they can then continue)
  • Have a maximum distance to update at determined by something like their saved graphics quality & framerate

For anyone in the future, I’m using a .Heartbeat connection to manually update all of the beams visible, and when a new one is added I reset all of the offset.

1 Like