How to make gps arrow orbit around player indicator

I’m looking for a way for my gps arrow point towards a destination (basically a part), but orbits the player indicator (not only rotate)

this is what im stuck with:
(i have zero knowledge about trigonometry so this is pure AI)

External Media

image

image

(i want it to orbit like that)

Does anyone have any idea on how to make this? thanks

Hey, so this may not be the most performant option, it may not also look the best, but its an option!

You can use Normals to get a direction, and apply the normal as an offset to the part combined with a CFrame.LookAt to get the arrow pointing the right way.

Whats a normal? Well, you can think of it as an arrow starting at A pointing towards B.

To get the “Normal” you want, take the players position and remove the target position, and you’ll want to use .Unit on it to round it down to 1.

local normal = (Player.Character.PrimaryPart.Position - TargetPosition).Unit

Then, you want to know how far away you want the arrow from the player, you’ll multiply the normal by the distance.

normal *= 5 -- 5 studs away

Then to actually position the arrow (make sure its front face is correct), use CFrame.LookAt.

Arrow.CFrame = CFrame.LookAt(CharacterPosition, CharacterPosition+Normal, Vector3.new(0,1,0)

So to sum it up, you should have a function like this:

function positionArrow(Arrow: BasePart)
	local distanceFromPlayer = 5 --// 5 studs away
	
	--// Get the start position, the player's position
	local startPosition = Player.Character.PrimaryPart.Position
	
	--// Create the "Normal"
	local normal = (startPosition - TargetPosition).Unit
	
	--// Multiply the normal by the distance, which will position the arrow at a desired max distance.
	normal *= distanceFromPlayer
	
	--// Finally, set the position of the arrow.
	Arrow.CFrame = CFrame.LookAt(startPosition, startPosition + Normal, Vector3.new(0,1,0)
end

Here’s an example on how to call that function:

local runService = game:GetService("RunService")

runService:BindToRenderStep("UpdateArrow", Enum.RenderPriority.Last.Value, function()
	 --// This will work, assuming that your arrow is under Workspace and called "Arrow", AND that you have a variable elsewhere in the code called "TargetPosition"
	positionArrow(workspace:WaitForChild("Arrow"))
end)

If you want to make the arrow move smoothly, you can throw TweenService in by replacing the last line in the function.

tweenService:Create(Arrow, TweenInfo.new(0.2), {["CFrame"] = CFrame.LookAt(startPosition, startPosition + Normal, Vector3.new(0,1,0)):Play()

And here’s everything fully combined (In a local script):

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local deathConnection
local runService = game:GetService("RunService")

function positionArrow(Arrow: BasePart)
	local distanceFromPlayer = 5 --// 5 studs away, feel free to alter this.
	local TargetPosition = Vector3.new(100, 20, 170) --// Replace this with your method to get the targer position.
	
	--// Get the start position, the player's position
	local startPosition = Player.Character.PrimaryPart.Position
	
	--// Create the "Normal"
	local normal = (startPosition - TargetPosition).Unit
	
	--// Multiply the normal by the distance, which will position the arrow at a desired max distance.
	normal *= distanceFromPlayer
	
	--// Finally, set the position of the arrow.
	Arrow.CFrame = CFrame.LookAt(startPosition, startPosition + Normal, Vector3.new(0,1,0)
end

runService:BindToRenderStep("UpdateArrow", Enum.RenderPriority.Last.Value, function()
	 --// This will work, assuming that your arrow is under Workspace and called "Arrow"
	positionArrow(workspace:WaitForChild("Arrow"))
end)

--// Added function to unbind events
deathConnection = character:WaitForChild("Humanoid").Died:Connect(function)
	runService:UnbindFromRenderStep("UpdateArrow")
	deathConnection:Disconnect()
end)

Don’t rely on AI to code, you should learn how to code yourself as in reality you aren’t going to be getting far if you try to get AI to do everything for you.