I recently made a script that makes it so that a part’s front face constantly looks at the player. It works, but I was wondering if there was any other way that is more efficent and smoother than constantly changing the CFrame in a loop.
-- "Part" is the part that turns towards the player
-- "Head" is the player's head.
while true do
Part.CFrame = CFrame.new(Part.Position, Head.Position)
wait()
end
1 Like
Well you should use lerp which uses CFrame
you can try something like
while true do
task.wait()
Part:Lerp(Part.Position, Head.Position
end
I’ll send a working example.
edit, I believe your way is good but tween is also a good choice
1 Like
Instead of while loop use RunService.RenderStepped
RunService.RenderStepped:Connect(function()
Part.CFrame = CFrame.new(Part.Position, Head.Position)
end)
1 Like
Oh yeah i forgot abt runservice lol
Lol thx I keep forgetting that Lerp is a thing
Thanks. I was hoping there would be something less awkward then a while loop
You could also use TweenService its what I use for smooth draggable objects/ui.
RunService.RenderStepped:Connect(function()
local newCFrame = CFrame.new(Part.Position, Head.Position)
TweenService:Create(Part, TweenInfo.new(0.2), {CFrame = newCFrame}):Play()
end)
1 Like