I’m trying to figure out how to get the interpolation value from Point A to Point B with a defined alpha while also following a circular path created from a pivot point.
I can only think of a hacky way, I am curious if anyone has a proper solution.
I currently have my code (example below) lerping the CFrame every RenderStep, creating the actual path if Point B were to move fast enough, but I need a solution to follow the expected path.
local radius = 10
local speed = 10
local angleToInterpolateTo = 90
while true do
local dt = game:GetService("RunService").Heartbeat:Wait() -- Or Renderstep
local _, Y, _ = workspace.RotationPart.CFrame:ToOrientation()
if Y < math.rad(angleToInterpolateTo) then
workspace.RotationPart.CFrame = workspace.Pivot.CFrame * CFrame.Angles(0, (math.rad(speed * dt) + Y) , 0)
workspace.RotationPart.Position = workspace.Pivot.CFrame:PointToWorldSpace(workspace.RotationPart.CFrame.LookVector * radius)
else
break
end
end
radius Is how much you want it to be away from the pivot. speed Is the interpolation speed, and angleToInterpolateTo is the angle that you want to interpolate to.
EDIT: Also, I’m sure there is a better way to do this, but I’m not that good with CFrame and angle math so I tried my best lol.
Sorry, it’s not what I was looking for.
I’m essentially trying to achieve lerping but with a circular path, essentially getting a position with a defined alpha to achieve the effect in the diagram
I appreciate the help, but I’m working with a 3D space.
I essentially want the CFrame value between 2 points in a circular path. Title is a bit misleading, I’ll fix it shortly after this reply goes up.
Just imagine getting the value between 0-1 with an alpha of 0.5 but repeat it a couple of times,
function lerp(a, b, alpha)
return a + (b - a) * alpha
end
local c
for i = 1, 100 do
c = lerp(0, 1, 0.5)
print(c)
end
-- 0.5, 0.75, 0.875, 0.9375, 0.96875, etc.
It is essentially the same logic I use for my camera lerping but it doesn’t follow a circular path which I need.
If this is for a camera track, then you should be using Bezier curves to make spherical movements. Here is an example using a camera track creator plugin I made with Beziers.
Hopefully this image can clear things up. I’m essentially trying to grab a lerp(?) value using an alpha from the red point to the blue point, just following the curved path.
I’m confused how your example is any different from my above solution. There still exists only a 2D plane between those points and my code can just be rotated to fit that plane.
There is no “3D” rotation going on in spherical interpolating (called slerping)
On which plane a theta exists between the points that can be rotated in 2D.
Which will cause the point to move along the arc of the sphere.
Yes, which is why I’m looking into your 1st solution right now haha. I don’t mean a 3 axes rotation, I just meant I’m working on a 3D environment and getting the alpha instead of actually moving it. Sorry, brain go boom lol
Sorry, I guess I should really be posting your final solution.
You can use :lerp() for this, but you have to apply the principle that all circles have a constant radius. Please see the place file attached to test at your convenience (and for anyone else who wants to slerp a position on a 3D plane).