I am trying to create a radar GUI for the player to use while he or she is navigating. The radar has an icon on it that is supposed to represent the player and it is shaped like an arrow. The arrow is supposed to point in whatever direction that the player is facing.
I have created a script that does this, but with a little problem; when the icon rotates, after it hits about 90 degrees, it'll rotate in the backwards direction. I noticed that when the player is rotating, the Rotation property of any part can only reach 180 degrees while the Rotation property of the GUI can reach 360 degrees. This probably has to do with why the GUI icon does this.
How can I change this script to make it so that the GUI icon continues to rotate past the 90 degree limit and properly conforms to the player's rotation?
while true do r = script.Parent.Parent.Parent.Parent.Parent.Parent.Character.Torso.Rotation.Y wait(.01) script.Parent.Rotation = -r --I made this negative because when I tested it without the negative, the icon rotated backwards to the player's rotation. end
Instead of using the Y component of the rotation, you should use the heading of the character. To calculate this all you need to do is take the arc tangent of the x and z components of the Torso's lookVector. This will give you the heading in radians so you'll have to convert to degrees.
local direction = part1.CFrame.lookVector local heading = math.atan2(direction.x, direction.z) heading = math.deg(heading)
Now you have the angle, all you have to do is apply it to the GUI.