Locating a goal and giving its position with degrees

Hello,

(First, English is not my first language so sorry if you have a hard time understading what I mean.)

I want a system that can locate any event on my map and tell me at how much degrees is that event from the player.

Here is an example :

Spoiler
In this pcture the target (or goal ) is the event in the center of the map.

The player is at the down-left corner.

In game, I would want the game to tell me that, in this very situation, the event is at (aproximatively) 135° of the player.

If it is impossible to realize a system like with event or with only minors scripts changes, I will move this to the script request section.

Thanks for taking the time to read this.

EDIT : ( I cannot reply to this because I have exceeded 2 posts today. ) First, thanks for your help. And, when you will remenber about those formulae, can you please inform me on how to do that system with event ?
Yes, it is possible.


You just need a lot of mathematics in control variable commands...


You'll need four variables to store the X and Y for both player and target, then a few more for temporary calculations and the trigonometric formulae.


It'll be a bit tricky to calculate the angle (especially due to the limit for integer numbers) and I don't remember those formulae right now, but it can be done...
Hello! Open the script editor and paste the following code in a new slot above Main:

class Game_Interpreter def angle_from_player(id) event = $game_map.events[id] (Math.atan2($game_player.y - event.y, $game_player.x - event.x) * 57.29577951308232) % 360 end endTo try it, put the following in a Script command in a Parallel Process event:

p angle_from_player(id)Change id for the actual event ID (1, 2, 3, 4, etcetera).
Thanks you so much for this @Source it works great ! I just got a little problem : I need the angle to be an integer number. Do you think you can change that, please ?
Hello! Yes, use the following code instead:

class Game_Interpreter def angle_from_player(id) event = $game_map.events[id] ((Math.atan2($game_player.y - event.y, $game_player.x - event.x) * 57.29577951308232) % 360).to_i end endCheers 🙂
Thanks again.
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/locating-a-goal-and-giving-its-position-with-degrees.39467/