Creating Longer Trails w/ Parts & Beams

Nope, the Server is the one completely responsible for creating the markers, beams, everything. Yet the Client is the one choking on this.

bro are you making a nuclear weapon? what do you require a longer trail for, just wondering

The distance can get absurdly far, replicating 50,000 Miles in a single stud. 20 seconds isn’t long enough to be able to acknowledge the entire trail of an object that COULD also be moving in real time at a scale this big.

1 Like

I suggest you use the micro profiler to find out what exactly is causing the lag, and then go from there. With the limited information I have I cant help much. Its probably due to the scale of everything or an issue in your implementation but I have no way of actually knowing.

Considering everything is practically the same as you left it, other than what part is referenced, I’d imagine it could be the scale of things and what not. I will use the micro profiler, and see what I discover, and leave updates here maybe.

I’m open to new comments, suggestions, ideas and solutions to this issue still though.

About how many markers exist at any given time? You might want to try caching parts if many markers are being created and destroyed. PartCache, for all your quick part-creation needs - #89 by NinjoOnline Never used the module but just remembered seeing it a while ago

I said, about 3,000 parts. I’ll take a look at this post shortly.

I think using EditableMeshes as beams could be an option. I have not used them myself so I am unsure of their performance but they are dynamic and probably more performant than my previous implementation.

as a replacement for typical Parts?

Sorry for the delay, you can use them instead of the parts and the beam. It allows you to use one instance for the entire trail. In addition to that, algorithms that simplify and optimize mesh geometry are super easy to find and very performant.

You mean one single mesh makes up the geometry and length of the entire trail?

Yes, I think that may work well for you. I’m trying it out right now.

I’m having a difficult time understanding this new feature. lol, I have not done much with standalone meshes as it is.

Its currently in beta with very little proper documentation. When I’m done testing things out I will send my code with comments, hopefully it helps. Because EditableMeshes follow the standard convention of meshes you can look at external sources on how they work.

Alright sounds good, I’ll keep messing around with them in the meantime, thanks!

Still a WIP but its working right now. I’ll probably continue working on it tomorrow

It is a module script

Planning on adding the ability to remove markers, and allow fading them out over time and maybe some other stuff
Also fixing the math so that when you look along the beam from one end the triangles dont distort

also will add comments in the final version whenever I make that

local replicated_storage = game:GetService("ReplicatedStorage")


local Trail = {}
Trail.__index = Trail

local TrailsFacingCamera = {}




game:GetService("RunService").RenderStepped:Connect(function(dt)

	local CameraLook = workspace.CurrentCamera.CFrame.LookVector



	for _,Trail in TrailsFacingCamera do
		for i,Marker in Trail.Markers do
			local Mesh:EditableMesh = Trail.EditableMesh
			local OriginalMesh:MeshPart = Trail.Mesh

			local offset

			if i == #Trail.Markers then
				offset = CameraLook:Cross(Marker.Direction).Unit * Trail.Width
			else
				offset = CameraLook:Cross((Marker.Direction+Trail.Markers[i+1].Direction)/2).Unit * Trail.Width
			end


			Mesh:SetPosition(Marker.Associated_Vertices[1],OriginalMesh.CFrame:PointToObjectSpace(Marker.Position+offset))
			Mesh:SetPosition(Marker.Associated_Vertices[2],OriginalMesh.CFrame:PointToObjectSpace(Marker.Position-offset))

		end
	end



end)


function Trail.new(Width:number,FaceCamera:boolean, StartingPoint:Vector3)

	local T = setmetatable({}, Trail)

	T.Width = Width

	T.FaceCamera = FaceCamera

	T.Mesh = Instance.new("MeshPart")
	T.Mesh.Anchored = true
	T.Mesh.CanCollide = false
	T.Mesh.CanTouch = false
	T.Mesh.CanQuery = false
	--T.Mesh.Material = Enum.Material.Neon

	T.Mesh.Size = Vector3.one



	T.Mesh.Parent = workspace:WaitForChild("Trail_Folder")


	T.EditableMesh = Instance.new("EditableMesh",T.Mesh) -- setting parent in constructor is usually bad practice, but here its fine because no properties are being modified after initialization and before parenting



	T.Markers = {}


	if StartingPoint then
		T:AddMarker(StartingPoint)
	end



	if FaceCamera then
		table.insert(TrailsFacingCamera,T)
	end

	return T
end





function Trail:AddMarker(point:Vector3)
	local Marker = {}

	local Mesh = self.EditableMesh

	local OriginalMesh = self.Mesh

	local offset = Vector3.new(0,1,0)*self.Width



	Marker.Position = point





	Marker.Associated_Vertices = {Mesh:AddVertex(OriginalMesh.CFrame:PointToObjectSpace(point+offset)),Mesh:AddVertex(OriginalMesh.CFrame:PointToObjectSpace(point-offset))} -- add two vertices for each marker


	if #self.Markers ~= 0 then




		local LastMarker = self.Markers[#self.Markers]


		Marker.Direction = (LastMarker.Position - Marker.Position)


		Mesh:AddTriangle(
			Marker.Associated_Vertices[1],
			Marker.Associated_Vertices[2],
			LastMarker.Associated_Vertices[1]
		)
		Mesh:AddTriangle(
			LastMarker.Associated_Vertices[1],
			LastMarker.Associated_Vertices[2],
			Marker.Associated_Vertices[2]
		)

		Mesh:AddTriangle(
			LastMarker.Associated_Vertices[1],
			Marker.Associated_Vertices[2],
			Marker.Associated_Vertices[1]
		)
		Mesh:AddTriangle(
			Marker.Associated_Vertices[2],
			LastMarker.Associated_Vertices[2],
			LastMarker.Associated_Vertices[1]
		)

	end

	if #self.Markers == 1 then
		self.Markers[1].Direction = Marker.Direction
	end



	table.insert(self.Markers,Marker)


	--print(self.Property)
end

return Trail

In a local script somewhere


local one = workspace:WaitForChild("1")
local two = workspace:WaitForChild("2")
local three = workspace:WaitForChild("3")

local ReplicatedStorage  = game:GetService("ReplicatedStorage")
local Trail = require(ReplicatedStorage:WaitForChild("Trail"))


local trail1 = Trail.new(2,true,one.Position)


trail1:AddMarker(two.Position)
trail1:AddMarker(three.Position)

1 Like

I appreciate you taking the time to do all of this, this should set a pretty good example at what I need to do, you don’t need to finish it or send me a final product if you don’t want to unless you deem it necessary for major things that I should know about, but I’ll mess around with what you made and all, thank you

So it’s been some time, and a few days ago I put in place what you designed. I also added a trail length based on distance from the part moving so the trail dissipates. This isn’t so bad at first, but after 30 to 45 seconds depending on how many trails, it begins to lag, but I don’t know why it would if it’s perfectly fine in the first 30 seconds and the trails are at their full length.

Are you sure the trails are the issue, and that there isn’t anything else that could be causing the lag? Sorry for the delay I haven’t been too active on the dev forum, my discord user is redevan if you want to shoot me a dm there, ill be able to reply much more quickly.