I am making a video game using Game Maker Studio 2.0 and am making a radar. To give you some background, one object is obj_Player, and the other is obj_Sub. The radar gives the sub's position and distance from the player (center of radar).(adsbygoogle = window.adsbygoogle || []).push({});

The first part of my radar works perfect. I normalized the screen size to fit the radar size, and it shows the dots on the radar perfectly as long as the target is on screen. FYI, my radar is in bearing mode rather than angle mode, so it starts at 12 o'clock and sweeps clockwise, rather than a unit circle which starts at 3 and sweeps CCW.

The second part of it, I have run into some trouble. I don't believe the program uses polar coordinates, so I am restricted to cartesian.The second part of it, if the target is offscreen, I want the dot to be on the edge of the radar and get bigger and bigger until the target comes on screen (at which point I have a working model for).

The code I have is below, and executed every frame:

x = obj_Radar.x + (sin(arctan((obj_Player.y - obj_Sub.y)/(obj_Sub.x - obj_Player.x))) * (0.65 * 139));

y = obj_Radar.y + (-cos(arctan((obj_Player.y - obj_Sub.y)/(obj_Sub.x - obj_Player.x))) * (0.65 * 139));

Where obj_Radar.x is the radar x center coordinate

obj_Radar.y is the radar y center coordinate

obj_Player.x is the player x coordinate

obj_Player.y is the player y coordinate

obj_Sub.x is the sub x coordinate

obj_Sub.y is the y coordinate

Basically, the first part of the equation (obj_Radar.x and obj_Radar.y), I am have it start at the center of the radar, then adding the necessary values.

Now, you might be asking yourself "Why is he using sin for the x coordinate and not the y". That is because I am using a bearing and the course and direction is perpendicular to the radar's x and y system. But this may not be relevant for the trouble shooting I am doing.

Anyway, I am looking for the radius to stay constant (at the edge of the radar), but to show the angle between the offscreen target and the player. For some reason that is beyond me, the radius doesn't stay constant.

Inside the arctan function, you have the difference between the target and player's y divided by the difference between the target and player's x (opposite over adjacent), which should give me the angle of this triangle. I then take the sin / cos of it to give me y / x component of it and then multiple by the radius (0.65 * 139).

So, can anyone tell me where I went wrong and why my radius is not constant here? Thank you very much.

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# I Using trigonometry to create a radar for a game.

Have something to add?

Draft saved
Draft deleted

Loading...

Similar Threads - Using trigonometry create | Date |
---|---|

I Which x_0 to use in a Taylor series expansion? | Feb 19, 2018 |

I Find the height up a ladder where a dropped bottle will break, using only two bottles | Feb 6, 2018 |

B Using trig to find distance? | Jan 18, 2018 |

How to find the X coordinate of a point using trigonometry? | Sep 20, 2013 |

Obtaining pi through use of trigonometry and limits | Jul 2, 2012 |

**Physics Forums - The Fusion of Science and Community**