Lerping CFrame along "longer" arc

Hi there roblox mathmeticians,

I’m curious if anyone can help me solve a tricky problem. I’m trying to get a part to lerp along two CFrames in this fashion:

image

However, CFrame:Lerp() follows the most obvious, shortest path:

image

For clarification, these two points do not align to a circle.

4 Likes

You can create multiple parts that will be the lerping points, like, lerp the part to every lerping point.
Like this:

red dot is a lerping point

1 Like

Thanks for the reply. What I think you are suggesting is the following:

image

I’ve tried this and got weird results with the rotations alternating back and forth between each point. This would be solved by adding more lerping points where the distance is shorter following the lower arc. The problem is that I need to predefine many of these arcs, so I would be polluting my workspace with hundreds and hundreds of reference parts.

If there is no trivial mathematical solution, this is probably what I will do.

What I would do is use a spline to define a “smooth” curve. By essentially defining points along a curve, you can then receive an equation which smoothly fits through these points. Then, parameterize it for a single variable, such as t. You can then iterate from [0, 1] along the curve.

Here is a brief Wikipedia entry about splines: Spline interpolation - Wikipedia

If you are just moving something in a circular manner, you could just use Sine and Cosine to determine the x, y and rotation of the object along the circular path.

You can just change the rotation while lerping. Like this:

local part = workspace.Part
for i = 0,1,0.01 do
part.CFrame = part.CFrame:Lerp(workspace.LerpingPoint1.CFrame * CFrame.Angles(workspace.LerpingPoint1.Orientation),i)
wait()
end

You can lerp the part to the rotation of the sleeping point.

I would avoid doing this if you favor quality over simplicity. While this approach is intuitive and simple, it will visibly stutter as the direction abruptly changes after each waypoint.

Interesting solution. I get over the stuttering by using Heartbeat to iterate between [0, 1]. However,

CFrame.Angles(workspace.LerpingPoint1.Orientation)

gives me an “Argument 3 missing or nil” error and otherwise inputting the angle gives me the same arc as above.

Thanks for the link! I will check out splines and get back to you guys on how my implementation worked. Unfortunately as I mentioned earlier, these two points are not aligned to a circle, more of an ellipse.

Yes I know, I found a way to fix it, but it is not setting it to the exact rotation, to fix it, you can do this:

local lerpedPart = workspace.LerpedPart 
for i = 1,#workspace.LerpPoints:GetChildren(),1 do
	local part = workspace.LerpPoints:WaitForChild("Lerp".. i)
	for j = 0,1,0.01 do
		lerpedPart.CFrame = lerpedPart.CFrame:Lerp(part.CFrame * CFrame.Angles(math.rad(part.Orientation.X), math.rad(part.Orientation.Y), math.rad(part.Orientation.Z)), j)
		wait()
	end
end

I am not sure if the math.rad is needed, but I am testing something with it.

This is how I tested my earlier reply, and it gives me a really interesting arc:

https://gyazo.com/8619f3780c767d95d861672423a862a7

Edit: I’m fairly certain that multiplying a CFrame by its own angles is just going to transform it into a different CFrame that is not the desired outcome.

Same, I am trying to figure out why.

I would avoid using CFrame.Angles. You can just directly extract out the rotational component of the CFrame. If you really want to go from CFrame->Angles->CFrame, you should extract the angles directly from the CFrame and not use Orientation property.

For your instance, what I would do is a little something like this:


You find p1, you can do this by physically going and finding it in workspace as oppose to coding it; however that’s your prefference.

You rotate your part relative to ‘p1’ and in theory, it should re-create the same effect.