Bending parts to equations

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want to have a function that, when I input a equation. Bends a part to have the shape of the equation.

  1. What is the issue? Include screenshots / videos if possible!

I have no idea how to bend parts. I’ve seen it used, but don’t know how.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Somehow no-one has ever asked this question, so I didnt find much context

Try this:

-- Define a function to create a smooth curve
local function SmoothCurve(t)
    -- Define the equation here
    local x = math.sin(t)
    local y = math.cos(t)
    local z = t  -- Example: z-axis follows linear function
    
    return Vector3.new(x, y, z)
end

-- Create parts along the curve
local numPoints = 10
local parts = {}

for i = 1, numPoints do
    local part = Instance.new("Part")
    part.Position = SmoothCurve(i / numPoints)
    part.Parent = workspace
    parts[i] = part
end

-- Attach parts with Motor6D constraints
for i = 1, numPoints - 1 do
    local motor = Instance.new("Motor6D")
    motor.Part0 = parts[i]
    motor.Part1 = parts[i + 1]
    motor.C0 = CFrame.new(parts[i].Position)
    motor.C1 = CFrame.new(parts[i + 1].Position)
    motor.Parent = parts[i]
end

-- Update parts positions (optional, depends on your implementation)
while true do
    for i, part in ipairs(parts) do
        part.Position = SmoothCurve(i / numPoints)
    end
    wait(0.1)  -- Adjust the wait time as needed
end

i used chatgpt because i dont know anything about bending parts to equations

You can try using editable meshes to displace each vertex in a mesh depending on its position.

If you or OP come up with any example .rbxl to check out that would be sweet!

EditableMesh offset.rbxl (55.7 KB)
The only issue with this method is that Roblox doesn’t support editable meshes in live experiences yet, so you would have to wait for that.

Interesting topic!
You cant bend a part itself; however, you can create a bunch of points across a curve and then you can use parts to connect each point to the next point to create a “curve.” I believe in your ability to fill in the part between each point, there are many resources online for that, but if you get stuck on that part feel free to hit me up again and I can help with that part.

As to take care of the first part we should first generate the “keyframes.” For this I will be assuming the “equations” you are referencing will be the quadratic equations or y=ax^2 + bx + c, if this is true I have come up with the following simple function to turn this into code:

function generateKeyframes(quad_term, linear_term, const, length, gap) -- input slope and y-intercept
	local points = {}
	for x=-(length/2),length/2,gap do
		local y = quad_term*x^2 + linear_term*x + const
		table.insert(points, {["x"]=x,["y"]=y})
	end
	return points
end

Parameters:

  • quad_term = ax^2
  • linear_term = bx
  • constant = c
  • length = the amount of keyframes you want to have total
  • gap = the increment in the x value for each keyframe

This function returns a table with the keyframes, a sample for this would look like:

{
    {
        ["x"] = 0,
        ["y"] = 5,
    },
    {
        ["x"] = 1,
        ["y"] = 5.9,
    }
}

Anyways, with these keyframes in place it is easy to generate parts across this curve:

function placeParts(partCount)
	local keyframes = generateKeyframes(0.9, 0, 5, partCount, 0.5)
	
	local count = 1
	for _, keyframe in keyframes do
		local part = Instance.new("Part")
		part.Position = Vector3.new(keyframe.x, keyframe.y, -20)
		part.Anchored = true
		part.Size = Vector3.one
		part.Shape = Enum.PartType.Ball
		part.Name = "Part"..count
		part.Parent = workspace
		
		count += 1
	end
end

Very simple function, I dont think I need to explain anything. Anyways, we can now call this function
placeParts(200) -- this will use 200 parts to display the curve

With this program in place, the results should look like this:


As briefly mentioned in the beginning, the only part missing from this would be to connect the keys here with parts to make it look like 1 curve, once again, let me know if you need more help with that.

You can use a rigged block mesh and set the bones to where you want it to be bendable.