Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

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

Asked by 10 years ago

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

Log in to vote
3
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

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.

0
That works. Thank you. Scriptos 45 — 10y
Ad

Answer this question