✓ Accepted answer
I would use the lerp function in ROBLOX.
To use lerp, you get a start point, or CFrame in this case, and an end point, and lerp though them.
So we know the start point. It'll be the brick, or whatever you're looking to rotate.
local partToLookAt = workspace.Part2
local part = workspace.Part
local start = part.CFrame
Now to get the finish, we can make a newCFrame, looking at partToLookAt, like this:
local partToLookAt = workspace.Part2
local part = workspace.Part
local start = part.CFrame
local finish = CFrame.new(part.Position, partToLookAt.Position)
> CFrame.new(position, look-at)
Then, we can lerp them in a for loop!
local partToLookAt = workspace.Part2
local part = workspace.Part
local start = part.CFrame
local finish = CFrame.new(part.Position, partToLookAt.Position)
for i = 0,1,0.03 do
part.CFrame = start:lerp(finish, i)
wait()
end
And we're done!
1 comment
Good answer, however it's noteworthy to mention that delta time should be used as progression of the animation, tween, lerp, etc (opposed to wait). Subsequently, it should be used with RunService so it's in sync with the processing of the client.