# Smooth rotation problem

4.2.2

### Question

I have some extremly simple code that rotates a 3dNode 90 degs clockwise or anticlockwise. It works fine but what I really want to do is complete the rotation slowly over time rather than instantly rotate.

I’ve tried using lerp angle but I cant seem to get it to rotate the full 90 degrees and I am now very confused!

Here is my code -

extends Node3D

func _process(delta):
if Input.is_action_just_pressed(“rotate_camera_cw”):
if Input.is_action_just_pressed(“rotate_camera_acw”):

If you want rotation to be smooth and controlled by the player you could use `Input.is_action_pressed` and rotate small amounts multiplied by delta.

If you are not looking for smooth controlled rotation, try a tween here? One issue will be interrupting the tween, you may need a timer or boolean to track if the animation is in progress.

``````const rotation_time: float = 2.0 # in seconds

func _input(event: InputEvent) -> void:
if event.is_action_pressed("rotate_camera_cw"):
var rotate_tween := create_tween()
rotate_tween.tween_property(self, "rotation:y", rotation.y + PI/4, rotation_time)
elif event.is_action_pressed("rotate_camera_acw"):
var rotate_tween := create_tween()
rotate_tween.tween_property(self, "rotation:y", rotation.y - PI/4, rotation_time)
``````
1 Like

You can use lerp_angle for a smooth rotation, like I demonstrated in this video.

1 Like

Thank you for your response, i’m not going to be able to try this until later but really appreciate it and I’ll let you know if it works.

Great video I think I have been missunderstanding lerp angle so I’ll give this a go later too, seems to really match what I am trying to do.

1 Like

Actually decided to quickly have a go with this and worked perfectly. Thanks so much, I just made a couple of tweaks to the rotation amount (PI/2) and the time

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.