How would I get a Gui LookVector?

Hello!
So, I’ve been reading this article which solved one of my problem about the rotation of the gui. However, in the game they will be multiple arrows so I cannot make it stay on the same position. Which to do that, you must have a Lookvector of the Gui Position first, this is what I mean:
image
local middle part is the arrow which is without a red box, the red box one is the one we need to find.
Please help!

1 Like

So you want the arrow to point towards the red box, correct? Or towards every player in the game, like in the article?

1 Like

so what you can do is add a UI element infront of the red box then get its absolute position
Note: Absoulute position is like global position

Getting the vector3
then u can use this Camera:ScreenPointToRay to get the vector3 if you do want

2 Likes

Yes, but make it go forward a little bit

Hmm, I still don’t get on what you mean. Can you explain further more?

So add a UI frame in the red box so i suppose that by default the arrow points upwards correct?
so put the frames size and pos to
{0,0,1,0} and {1,0,1,0} respectively
then what you can do is get the absoulute position of the frame and you will have a sort of lookvector i guess

If I have a problem explaining (Im not good at english sorry :sob: )

This is a gif i found like i want:


As you can see, it offsets from the middle part to the guard position

i mean yea it does but that doesnt look like use of lookvector for ui which doesnt exist

1 Like


Ok this is the process I used by getting the midpoint from the worldscreenposition and a middlescreen position.

I gotchu, but my laptop is still loading :smiling_face_with_tear:

1 Like

Something like this right? But offsetted from the middle?

1 Like

Kinda like this
https://i.gyazo.com/4ad190322d5752a1889ea19c4a0a992c.mp4

1 Like

Try this out

–Place in local script in startercharacter

--//VARIABLES
local Player = game.Players.LocalPlayer
local Camera = game.Workspace.CurrentCamera
local SavedViewportSize = Camera.ViewportSize/2
--//CREATE GUI
local Target = Instance.new('Part', game.Workspace)
	Target.Anchored = true
	Target.BrickColor = BrickColor.new('Really red')
	Target.Material = Enum.Material.Neon
	Target.Size = Vector3.new(2, 2, 2)
	Target.Position = Vector3.new(0, 4, 0)
local ScreenGui = Instance.new('ScreenGui', Player.PlayerGui)
local Frame = Instance.new('Frame', ScreenGui)
	Frame.BackgroundTransparency = 1
	Frame.AnchorPoint = Vector2.new(0.5, 0.5)
	Frame.Position = UDim2.fromScale(0.5, 0.5)
	Frame.Size = UDim2.fromScale(0.1, 0.1)
local TextLabel = Instance.new('TextLabel', Frame)
	TextLabel.AnchorPoint = Vector2.new(1, 0)
	TextLabel.BackgroundTransparency = 1
	TextLabel.Size = UDim2.fromScale(1, 1)
	TextLabel.Text = '<'
	TextLabel.TextScaled = true
--//FUNCTIONS
while game["Run Service"].RenderStepped:Wait() do
	local ToScreen		= Camera:WorldToScreenPoint(Target.Position)
	local Difference	= SavedViewportSize - Vector2.new(ToScreen.X, ToScreen.Y)
	local Angle		= math.atan2(Difference.Y, Difference.X)
	
	Frame.Rotation = math.deg(Angle)
end
1 Like

Omg, Tysm!! I dont know what to explain. Thank you!

1 Like

Need help making a damage direction GUI This one might be better