Collideable beams?

I want to make a collision for a beam using scripting but I don’t know how. How does roblox calculate their beams? Is there an easy way to do this?

(for your information, I want to make this collidable)

2 Likes

Roblox beams represent Bezier curves indrectly. You can use a Bezier curve algorithm to gather the points, and data from the attachments to calculate their orientation.

Here’s a function to gather the cubic bezier points from a beam:

local function getPoints(beam): {Vector3}
	local a0 = beam.Attachment0
	local a1 = beam.Attachment1

	local p0 = a0.WorldPosition
	local p3 = a1.WorldPosition

	local p1 = p0 + a0.WorldCFrame.RightVector * beam.CurveSize0
	local p2 = p3 - a1.WorldCFrame.XVector * beam.CurveSize1
	return { p0, p1, p2, p3 }
end

Here’s a recursive function that can be used to calculate a point along a bezier curve when given a table of the 4 points, although it works with any number of points.

local function bezier(points: {Vector3}, t: number): Vector3
	if #points == 1 then
		return points[1]
	end

	local newPoints = {}
	for i = 1, #points - 1 do
		newPoints[i] = points[i]:Lerp(points[i + 1], t)
	end

	return bezier(newPoints, t)
end

Here’s a little gif of a quadratic bezier, basically you just calculate a point a certain percentage between two repetitively until you are left with only one point.
bezier_2_big

3 Likes

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