I have a player which moves left, right and can jump. It moves based on where the user clicks, e.g. if the user clicks left, the player moves left. I have set a custom sprite to follow the mouse cursor. However, I want the cursor to rotate based on where it is relative to the player, for example when the cursor is to the left of the player it points left, and rotates as the cursor moves up or down. I also want the pivot point of the sprite to be the mouse cursor. So even though it rotates relative to it's distance and angle to the player sprite, the pivot point that it rotates around should be the mouse cursor.

Maths isn't exactly my strong point, so I was wondering if I could get some help? =)

Many thanks!

I haven't tried it myself, but have you tried using the look_at (documentation) function for this? You just need to pass it a position and then it will rotate the Node2D to point at it.

You might be able to use the look_at position and the player's position on the sprite for the mouse cursor, and then it should, theoretically, rotate to look at the player. That is what I would try at least. Hopefully this helps!

@TwistedTwigleg said: I haven't tried it myself, but have you tried using the look_at (documentation) function for this? You just need to pass it a position and then it will rotate the Node2D to point at it.

You might be able to use the look_at position and the player's position on the sprite for the mouse cursor, and then it should, theoretically, rotate to look at the player. That is what I would try at least. Hopefully this helps!

Wow, that did the trick! I simply attached a script to the parent node and did "$Mouse.look_at($Player.position)". Easy! Thank you!

3 years later