I'm trying to make a humanoid figure rotate to a brick. I used :
figure.HumanoidRootPart.CFrame = CFrame.new(figure.HumanoidRootPart.CFrame,game.workspace.Brick.Position)
I wanted it to keep rotating the HumanoidRootPart until it faces the brick. Is this possible? thanks.
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)
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!