Rotate Camera Smoothly?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By HaptikRevamp

Hello is there a way to make the camera rotate smoother, i am making a rotation for my camera by scratch to use with buttons since alot of tutorials only show Mouse most of the time and i got this from the Godot Docs:

However the rotation is mega violently fast and i cant figure out how to smooth it out or “Slow the rotation down”

this is the code im using:

rotate_object_local(Vector3(0, 1, 0), PI)
	transform = transform.orthonormalized()

How can i fix this?

:bust_in_silhouette: Reply From: MrEliptik

You need to lerp (linear interpolation) the transform, or use a tween if you want more control on the type of smoothing curve.

With lerp you could do something like this:

func _process(delta):
    transform = lerp(transform, new_transform, 0.2) 

You can set the new_transform somewhere in your code when a player is pressing a key or something. 0.2 means the value will be reduced by 20% each time the function is called. Adjust it to your liking

Tween: Tween — Documentation de Godot Engine (4.x) en français
Lerp: @GDScript — Documentation de Godot Engine (4.x) en français

:bust_in_silhouette: Reply From: magicalogic

If you call this in _process(delta),make sure you multiply the PI by delta.