how to delay my rotation?

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

hi everyone, how to delay rotation? what i meant is i want my arrow slowly rotate to my mouse direction.

func _process(delta: float) -> void:
	player_dir = get_parent().get_node("player").global_position - global_position
	global_rotation = player_dir.angle()

here video in youtube

:bust_in_silhouette: Reply From: wowzzers

Hi! Try the lerp function.

global_rotation = lerp(global_rotation, player_dir.angle(), delta * 2)

Use the lerp_angle function so your arrow doesn’t rotate the wrong direction.

Dlean Jeans | 2020-02-14 02:26

Thank you for the information!

wowzzers | 2020-02-14 14:22

:bust_in_silhouette: Reply From: Sween123

When you want to rotate, use a variable to save the target roation value.
Then use another bool variable, if it’s true, start rotating towards the target value.
For example in function _process(delta):

if needs_rotate:
    var rotation_speed = (target_rotation - rotation) / 100
    rotation += rotation_speed
    if abs(target_rotation - rotation) < rotation_speed:
        rotation = target_rotation
        needs_rotate = false

It’s a sample code, don’t copy paste the whole thing. Create variables and name them, set a different rotation speed by changing the number “100”, etc.