0 votes

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

in Engine by (352 points)
edited by

2 Answers

+1 vote

Hi! Try the lerp function.

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

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

Thank you for the information!

+1 vote

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.

by (760 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.