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.
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
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)
Thank you so much for the replies! It worked immediately and was very helpful.
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 >:(