How can I make this smoother?

How can I make this look smoother?

Basically, I have set the Camera CFrame to a part in workspace and the part is rotating to the player
This is the script (Local Script):

local part = workspace.View
local Player = game.Players.LocalPlayer

while wait() do
	game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
	game.Workspace.CurrentCamera.CFrame = part.CFrame
	part.CFrame = CFrame.new(part.Position, Player.Character:WaitForChild("Head").Position);
end

1 Like

I suggest using game:GetService("RunService").RenderStepped for loops instead of while wait() do.

1 Like

I recommend using RunService.RenderStepped instead of while wait() do, since it runs after every single frame

1 Like

Oops, great minds think alike!

3 Likes

Thank you! That was definitely much smoother!
Will remember renderstepped for next time!

1 Like

I would rather recommend RunService.Heartbeat rather then RunService.RenderStepped.

1 Like

How does Heartbeat differ from Renderstepped? I’ve actually never used heartbeat before

1 Like

Heartbeat fires AFTER the Physics completed meaning that it is more accurate than RenderStepped which would have a one frame delay from when the Player moves and when the Camera Positions its self.

1 Like

I see. I’ll keep that in mind when I’m using run service!

1 Like

Hmmm this is quite interesting, didn’t know about heartbeat.
Tried it out and it seems like there is a slight smoothness than renderstepped.
Thank you!

https://developer.roblox.com/en-us/api-reference/event/RunService/RenderStepped

only use RenderStepped for code that works with the camera or character . Otherwise, RunService.Heartbeat should be used.

You should use RenderStepped for camera manipulation.

In this cae @OP wants to make the Camera track the Player.
The Character is affected by Physics meaning that it’s position might not be the same as before Physics had been Calculated.
You can see the effect of this when setting the Characters position using RenderStepped compared to Heartbeat (2 different examples both in startercharacterscripts).

game:GetService("RunService").RenderStepped:Connect(function()
    script.Parent:PivotTo(CFrame.identity) --  choppy since the Character could move due to Physics until this is set again (RenderStepped is before Physics)
end)
game:GetService("RunService").Heartbeat:Connect(function()
    script.Parent:PivotTo(CFrame.identity) -- not choppy since it's set after Physics have completed
end)
2 Likes

But the character model’s pivot isn’t being set every frame, the client’s camera’s pivot is. Looking at the script setting the camera’s ‘CameraSubject’ property and the humanoid’s ‘CameraOffset’ property would suffice and be more performant.

2 Likes

I was talking about Physics related changes and not changes of Position directly made by scripts. Altough setting the Camera Type isn’t something I tought of.:slightly_smiling_face:.

1 Like