Smoothly rotating character?

Hello!

I’m trying to rotate the character to look where the camera is facing. I made it work but it’s a bit jittery (as you can see in the GIF below). How would I make it smoothly rotate?

Currently I’m using Heartbeat.


(PS. Don’t worry about the character not looking directly at the camera’s focus, that’s just the animation throwing it off. I’ll fix it later)

3 Likes

Try RenderStepped. Heartbeat is in sync with framerate after physics update while RenderStepped deals with rendering before hearbeat does, so using the latter in this case would be helpful.

10 Likes

You should look into Lerping the CFrame instead of directly setting it. It will result in a more smooth transition.

1 Like

Either use @Fm_Trick’s solution or you can use the Tween Service (although lerping is probably less computationally expensive over Tween Service).

I wouldn’t suggest TweenService for something like this, since you’d have to create an entire new Tween every frame. Lerping with an Alpha of about .6 should do the trick.

1 Like

I’ve tried TweenService and it overrides character movement, preventing you from moving.

How would lerping work if I’m calculating a new CF every frame? If I set the alpha to 0.6, wouldn’t that just rotate the character 60% of the way? I’m not sure how that would fix the jittering.

Just tried that and it worked! Thanks! :smiley:

This would be better if you were sending client updates to the server. (server lerps between given values)

1 Like

Ahh, nvm I realized how it would work. Every frame, it would bring the Hrp closer and closer to the goal, thus creating a smooth tween effect.

No, it’s not, did you mean to write something else than “server”? The only difference between Heartbeat/RenderStepped/Stepped is where in the frame they run, they have the same frequency (once per frame). Heartbeat on the client doesn’t run “in sync with the server”.

7 Likes

I recommend you put a BodyGyro in the HumanoidRootPart and update its CFrame on RenderStep. Limit the MaxTorque so that it can only rotate about the y-axis. The benefit to using a BodyGyro is that it handles the interpolation for you with easily customizable settings for torque and dampening.

I’ve already gotten it to work by directly setting the CFrame of the Hrp. I’ve tried lerping and using BodyGyro before, but I just don’t like the feel of it. I prefer instantly setting it in this case. But thanks!

1 Like

I worded that wrong. To quote zeuxcg, “Since our camera scripts run at RenderStepped, if your updates depend on camera in some way - e.g. you want to keep some object fixed relatively to camera - you’d have to run the updates in RenderStepped to avoid a single-frame lag. Other than that I don’t see a strong use case for RenderStepped.”

Essentially you would want to use RenderStepped for things linked to camera rendering (like this) since it runs camera/rending things before physics, it goes first in the order. (as opposed to Heartbeat).

I will correct the original post however.

One useful tip @Spynaz is to use :BindToRenderStep() since you can keep the events firing in sync using the RenderPriority parameter.

1 Like