How can I make a part slowly rotate towards facing another part?

Hi! :smile:

How can I make a part slowly rotate towards facing another part? Not instantly, but step-by-step, like tweening or lerping.
I would also prefer if specifically the part’s bottom face would rotate towards facing another part.

I am bad at vector maths, because of that I couldn’t come up with a solution, I’ve also searched for solutions in the internet but I didn’t understand anything at all for the same reason. :disappointed_relieved:

Thanks in advance,
Muuuuuun :D

as you can get a part to face another by doing

Part.CFrame = CFrame.new(Part.Position,lookat.Position)

with tweening, you can do something like this:

local ts = game:GetService("TweenService")
local part = workspace.Part
local properties = {CFrame = CFrame.new(part.Position,workspace.LookAt.Position)}
local tinfo = TweenInfo.new()

local tween = ts:Create(part,tinfo,properties)
tween:Play()

Alternatively, with lerp, you can do something like this:

local part = workspace.Part
local lookat = workspace.LookAt.Position
local steps = 20
local totalTime = 3
local inital = part.CFrame
local final = CFrame.new(part.Position,lookAt)

for i = 0,1,1/steps do
    part.CFrame = inital:lerp(final,i)
    wait(totalTime/steps)
end
5 Likes

As you stated, you can use TweenService . Here’s a good tutorial on one by Wrathsong. https://www.youtube.com/watch?v=95OVTdka00k&list=PLatbVFCcsDB8jgIzJ3a4_q6CeGnsD0rhf&index=14

Here are two posts by AxisAngles that should help you with CFrame, read the Vector one first
https://devforum.roblox.com/t/how-to-think-about-cframes/11743 https://devforum.roblox.com/t/how-to-think-about-vectors/11866

1 Like

Thanks for the quick and simple reply, it helped :smile:

It helped get the part to face another part. Though, how would I go about making the part’s bottom face the other part? (I asked that in the question too)

oh, you can rotate the part with CFrame.Angles() and rotate the part pi/2 radians (90) degrees on the X axis to essentially move the bottom face to where the front face wouldve been

local final = CFrame.new(part.Position,lookAt) * CFrame.Angles(math.pi/2,0,0)
3 Likes

Thank you so much for the replies! It worked immediately and was very helpful. :hugs:
I obviously didn’t understand any of the math you gave me but at least it works perfectly…

Have a great day! \o/

You have not capitalized a letter in your code which was the reason for an error >:(

2 Likes