Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Setting beam curve sizes from desired control point vectors?

Asked by
acreol 0
6 years ago

So pretty much I want to be able to set a beam’s bezier curve from two control points. The code below works at setting a beam’s curve sizes from the already existing beam’s world control points (conversion gotten from the wiki: http://wiki.roblox.com/index.php?title=API:Class/Beam/CurveSize0) but then when I uncomment the lines to set the control points to the origin vector, it glitches/fails to accomplish this.

local beam = workspace.a.Beam
local a0 = beam.Attachment0
local a1 = beam.Attachment1


local function toPos(attachment,curveSize)
    return attachment.WorldPosition - attachment.CFrame.rightVector * curveSize
end

local cf = CFrame.new
local rot = CFrame.Angles(0,math.pi/2,0)

local function toCurveSize(attachment,goal)
    goal = attachment.WorldPosition-goal
    local pos = attachment.Position

    return goal.Magnitude,cf(pos,pos+goal.Unit)*rot
end

local c0 = toPos(a0,beam.CurveSize0)
local c1 = toPos(a1,beam.CurveSize1)
--local c0 = Vector3.new(0,0,0)
--local c1 = Vector3.new(0,0,0)

beam.CurveSize0,a0.CFrame = toCurveSize(a0,c0)
beam.CurveSize1,a1.CFrame = toCurveSize(a1,c1)

Answer this question