Rotate sprite in the direction of movement

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Bob Dolan
:warning: Old Version Published before Godot 3 was released.

I am trying to rotate my Sprite node in the direction determined by a pair of start and finish positions. I have read up on the supported functions for this and I understand the math but I cannot seem to get this working correctly so I thought I would ask here since I feel I am missing something obvious.

Basically I need something like this:

func RotatePlayer(start, finish):
#calculate angle
set_rot(angle)

:bust_in_silhouette: Reply From: mollusca

Use the Vector2.angle_to_point(Vector2 to) function:

func RotatePlayer(start, finish):
    var angle = start.angle_to_point(finish)
    set_rot(angle)

If the Sprite is pointed backwards just swap start and finish.

Yup, that did it. I guess I was overthinking this one. I am constantly surprised by how much functionality is internal to Godot. Thanks for the answer.

Bob Dolan | 2017-10-29 13:15