Arrow Pointing System

Hello there.

I want to produce an ‘arrow navigation system’ but I’m struggling on the maths or methods required.

I am trying to make an arrow point directly to a target relative to the players CFrame.

Using the same method as roblox’s native beam system:

I’m not asking for any spoonfed code just some ideas/information that can aid this process.

Thanks!

Have you tried CFrame | Roblox Creator Documentation lookAt?

Thanks for the response. I’ll look into this shortly and get back to you.

You can use .Magnitude along with CFrame.lookAt(), heres an example (I’ve put guide comments which will be explained below)

First off, I’ve made 2 parts. The white being the locator part, and the red being the target part.


image
^ Thats how the workspace looks.

Now, you can copy and paste this code into starter character scripts, I will explain what it does.

local RunService = game:GetService("RunService") -- [1]

local locatorPart = workspace:WaitForChild("LocatorPart") -- [2]
local locatorTarget = workspace:WaitForChild("LocatorTarget")

-- [3]
local character = script.Parent

-- [4]
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

-- [5]
RunService:BindToRenderStep("LocatorMovement", Enum.RenderPriority.Character.Value, function(step)
	-- [6]
	local distance = (locatorTarget.Position - humanoidRootPart.Position).Magnitude
	
	locatorPart.Size = Vector3.new(1, 1, distance) -- [7]
	locatorPart.CFrame = CFrame.lookAt(humanoidRootPart.Position, locatorTarget.Position) * CFrame.new(0, 0, -distance / 2)  -- [8]
end)

At first this might look like a lot, but I’ll explain.

1) We get RunService, this will be used for constantly updating the locator part.
2) We get the locator part, and the target that we created before
3) We get the character
4) We get the humanoid root part, this is what is responsible for moving the player and its limbs
5) We bind a render step function, :BindToRenderStep (or even .RenderStepped) should always be used when updating visual items as it makes sure that the task scheduler renders it first. You can read more about BindToRenderStep and RenderStepped in their respective links.
6) We get the distance between the target and the humanoid root part, this will be what controls how large we resize the locator to.
7) We set the locator parts size to a vector3 which contains the distance we calculated!
8) Probably the most important step, we make the locator look from the humanoid root part, to the locator target!! We also need to offset it by “negative of half the distance”. This is really important, the reason is as follows:

Parts are sized from the center, if we don’t offset the part at all, we get this:

The reason we do -distance / 2 instead of distance / 2 is because for whatever reason, -Z is forward on roblox.
This is what happens if you do distance / 2

Obviously you will need to play around with how the arrows work, but I’ve attached a place file which should help you out.

Part Pointing System.rbxl (22.9 KB)

1 Like