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”):
rotate_y(deg_to_rad(90))
if Input.is_action_just_pressed(“rotate_camera_acw”):
rotate_y(-deg_to_rad(90))
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)
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