How to rotate a player towards the camera smoothly?

Ok so I am sorry for posting this as there are several posts of the same type already in this forum, but none of them seem to solve my issue…

So here is the problem…
For a weapon tool I am trying to make, I want it so that when the players equip it they look toward the camera

So here is my approach:-

game:GetService("RunService").HeartBeat:Connect(function(dt)
    local cameraDirection = camera.CFrame.LookVector
    root.CFrame = CFrame.new(root.CFrame.p, root.CFrame.p + Vector3.new(cameraDirection.x, 0, cameraDirection.z))
end)

It works, but it’s not a smooth rotation

Here are two clips to show you what I mean.

This is how it works:-
How-it-works

This is how I want it to work:-
How-to-work

Any help would be highly appreciated!
Thanks in advance. :+1:

Have you tried using RenderStepped instead of Heartbeat?

1 Like

Yes I have, it works the same way…
(I found this tip as the solution marked in an another post and tried it out… but it is still not at all smooth)

I tested it on a new place and it makes it not jitter anymore not sure why it isn’t working for you. Also I’m surprised .HeartBeat worked because it’s .Heartbeat.

Where the code for your camera?

Oops, I am sorry, actually in my actual code its Heartbeat but since it was lengthy, I wrote that myself while writing the post and I have a habit of that. (Since most of the object oriented languages do function like that and lua is an exception)

Let me try it once again by the way…

Ok, so it did not work in my case but I figured out why it worked for you…

Here is the clip in which I tried using RenderStepped :-
Not-smooth-again

As you can see, I have changed the humanoid’s camera offset property (to the shift lock humanoid camera offset)
But when the camera offset is not changed (ie Vector3.new(0, 0, 0)) it is smooth
(I am sure you didn’t change the CameraOffset property of the humanoid)

Here is the clip:-
Trial-with-default-offset

But I still want the camera offset to be changed as that’s how most of the third person shooters work.

Any idea why it happens?

Never mind, I changed the camera type to Scriptable and made my own mouse-lock TPS style camera… it works smoothly!

Thanks for your time! :+1: