Rotate sprite and move to mouse click position. 2D

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

My original question with some code which I made so far https://godotforums.org/discussion/29532/rotate-sprite-and-move-to-mouse-click-position-2d#latest

I have a sprite, I click somewhere and I want that sprite rotate to mouse click position and move there.

Code which perform correct moving but without rotation:

func set_move_target(target):
    target_pos = target
    angle_to_target = target_pos.angle()

func move_to_target(delta):
    velocity = Vector2(speed, 0).rotated(angle_to_target)
    return move_and_slide(velocity) 

func _process(delta):
        if Input.is_mouse_button_pressed(BUTTON_LEFT):
            set_move_target(get_local_mouse_position())

        if target_pos:
            move_to_target(delta)

If I add property rotation and set its value - eveything becomes chaotic, random moves, rotations, etc.
What’s wrong with my calculations and how to use properly godot features?