How to make a arrow in a viewport frame face a part

I have a arrow in a viewport frame. How do I rotate the arrow (or the viewport camera around the arrow) so the arrow is pointing at a part relative to where the players current camera is.

For example this arrow would point at a part if the part was too the left of the players camera view.
Screenshot_10

1 Like

Put this script inside the arrow in the viewport frame.

local PartToPointTo = ThePartYouWantToPointTo
while wait() do
     Script.Parent.Position = workspace.CurrentCamera.CFrame.LookVector * 2
     Script.Parent.CFrame = CFrame.new(Script.Parent.Position, PartToPointTo.Position)
end


This constantly makes the arrow face the part.

It need to be in relation to where the players current camera is pointing. This wont move it if I move the players camera

Can you elaborate more? I’m having a hard time understanding what you mean by that. NVM! I understand.

So I tried editing my most recent post’s script. I’m sorry for not getting it right the first time. DISCLAIMER: I do not have access to roblox studio currently and therefore can’t test these scripts. But hopefully these help you. Also make sure that the viewport’s current camera property is set to the workspace’s current camera.

No doesnt work just points in one direction, but thanks for trying.

My viewport has its own camera, its not using the current camera

Do you have a video of the code I put in? Like a video of testing it. This can help me look at what’s happening and makes it so much easier for me to help. Is this viewport frame a surface gui or is it a 2D gui?

The viewport is a screengui

local playerGui = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
local c = Instance.new("Camera")
c.Parent = playerGui.Job.ViewportFrame
playerGui.Job.ViewportFrame.CurrentCamera = c

while true do
	playerGui.Job.ViewportFrame.Pointer.Position = CustomCamera.camera.CFrame.LookVector * 2
	playerGui.Job.ViewportFrame.Pointer.CFrame = CFrame.new( playerGui.Job.ViewportFrame.Pointer.Position, workspace.Help.Position)
	game:GetService("RunService").Heartbeat:wait()
end

Why’s the viewport frame’s camera not the workspace player’s camera? Also what’s the custom camera variable?

It how the roblox dev site says to use them.

I wrote a custom player camera script, Customcamera.camera is just the players camera

Ok, you should try not using a new camera inside the viewport frame and just set the viewport frame’s current camera to the player’s camera. How does your custom camera work?

I tried that and its move the pointer so that i cant see it.

The custom camera is basically the same as the standard camera.

Ok, I don’t have access to roblox studio so I can’t help that well. Sorry I couldn’t help.

I figure it out in case anyone has the same problem

Basically I too the CFrame of the pointers position while looking at the part position - the players position.
I then multiplied that CFrame with the CFrame of the cameras angle.
Finally i set the pointers CFrame to this.

local cf = CFrame.new( pointer.Position, (player.Position - Part.Position)) * (camera.CFrame - camera.CFrame.Position)
playerGui.Job.ViewportFrame.Pointer.CFrame = cf

Might not be the best solution but it seems to be quite accurate.

1 Like