Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I make an ImageLabel rotate with the direction of the camera?

I'm working on a mini-map, but I'm having problems with making the arrow in the center rotate to match the camera's rotation.

( Like in any RPG mini-map. The arrow points towards the direction you're facing.)

I've tried using lookVector and :toEulerAnglesXYZ(), but neither seem to work correctly.

The two codes I've tried are;

local x,y = workspace.CurrentCamera.CoordinateFrame:toEulerAnglesXYZ(); 
script.Parent.Frame.Dot.Arrow.Rotation = math.deg(x); 

and


script.Parent.Frame.Dot.Arrow.Rotation = math.deg(workspace.CurrentCamera.CoordinateFrame.lookVector.X);  

1 answer

✓ Accepted answer

Relevant wiki article.

What you are looking for in the three shown in the above article is Heading, which, when looking from the top down as in a minimap, shows which direction on ROBLOX's xz plane the camera is facing.

local pip = script.Parent.Frame.Dot.Arrow

local sx, sy, sz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = Workspace.CurrentCamera.CoordinateFrame:components()
heading = math.atan2(m02, m22)

pip.Rotation = math.deg(heading)

Now, this will error if the camera is looking directly downwards, or directly upwards, since the heading will not be determinable. However, ROBLOX by default doesn't allow for this.

1 comment

0

That works. Thank you.

This discussion is preserved as it was. New answers, comments, and votes are closed.