Make sprite follow mouse cursor

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

I am currently following this tutorial video

it is a really simple scene, all I have is a node 2D root and a sprite. and this is my code

extends Sprite
var mousepositoion
  	
func _process(delta):
   	mousepositoion = get_local_mouse_position()
   	rotation+= mousepositoion.angle() * 0.1

which is the same as the video. But result from mine is different. Lets say if I move my cursor directly above the sprite, it would rotate to the left and if I move my cursor to the right, the it would face up. I am not sure what I did wrong here .

Note: I also tried look at which also have the same result. I am quite confused what I did wrong
Edit : I tried $Sprite.rotation= rad2deg(90.0) and result is strange, it didn’t rotate 90 degress rather it seems to rotate something like 92 degrees. I am scratching my head here

:bust_in_silhouette: Reply From: kidscancode

A rotation of 0 degrees represents pointing to the right (along the x-axis). Since the image you’re using is drawn pointing upwards, it’s going to be 90 degrees off from what look_at() is doing. Set the Sprite’s rotation in the Inspector to 90, and you’ll be fine.

BTW, rad2deg(90) converts 90 radians to degrees, which is 5156 degrees. What you want there is deg2rad().

Thank you so much for helping. I actually end up drawing a arrow point to right and it worked. It is nice to know the the origin is right facing. As for rad2deg…that was me just being stupid. Thanks again

lowpolygon | 2019-05-03 23:14