Calculate how much to rotate an image (Compass)

Hi All,

I have what I think should be a simple question on scripting. I have two images that represent a compass, one being the compass body and the other the compass needle overlaid on top. My plan is that the player will have the ability to hide/show this compass, and can switch between different named 'targets' on a field map, which would be a given event.

I am horrible at math, so was hoping if anyone could point out how to calculate the rotation needed for my needle image, given the player event's position and the target event's position? Examples:

Player is at 10,10

Target is at 10,5

...Then Needle image rotation is 0 degrees

Player is at 15, 15

Target is at 20, 10

...Then needle rotation is 45 degrees

Anyone? 
first, you need a function to convert radian to degree.

module Math def self.degree(radian)    return (radian.to_f/Math:😛I) * 180  endendthen you need to know y_distance and x_distance between two objects.

Math.degree(Math.atan2(range_y,range_x))range_y's is y distance between player and object position

And so do range_x.

That's what I've done back then when I tried to calculate the degree between two objects.

It's better to test it first in RGSS Console. I'm not quite sure actually

EDIT: just for note

Spoiler
Angle

The sprite's angle of rotation. Specifies up to 360 degrees of counterclockwise rotation. However, drawing a rotated sprite is time-consuming, so avoid overuse.
Thanks for the response there; something for me to work up to, though if it'll lag things up I may just have to give up on that idea.  🤔

Please feel free to close this thread off, mod-type people!
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/calculate-how-much-to-rotate-an-image-compass.16736/