Help positioning arrow

I need help on how to position my arrow so its offset a bit.
Here’s what I have now:
image_2022-12-21_164647355
And here’s what im trying to achieve:
image_2022-12-21_164843367

Im wondering how I could make the arrow be offset so its not just on the center. My current code:

local arrow = part:FindFirstChild("Arrow")
arrow.Size = Vector3.new(0.09,mag,3.6)
local pos = part.Position -- my current positioning method
local pos2 = mouse.Hit.Position --lookAt vector
arrow.CFrame = CFrame.new(pos, pos2) * CFrame.Angles(math.rad(0), math.rad(90), math.rad(90)) --construct cframe and rotate

All help is appreciated

Are you trying to offset the arrow? Sorry i don’t really understand + its night, But i could help

To offset the arrow, you can simply adjust the pos variable before using it to construct the CFrame . For example, you could add an offset vector to pos like this:

local offset = Vector3.new(0, 1, 0)  -- add an offset of (0, 1, 0) to the arrow's position
local pos = part.Position + offset  -- adjust the position by the offset

You can adjust the values of the offset vector to move the arrow in different directions. For example, setting the offset to Vector3.new(1, 0, 0) would move the arrow 1 unit to the right, while Vector3.new(0, 0, 1) would move the arrow 1 unit forward.

this is how i see it sorry if I’m completely wrong lol

Maybe positioning the pivot point to the edge of it and setting the cframe to the cframe of the part by pivot would work? Not sure if that’s how it works because I’ve never used that method to position things

im trying to get it so the end of the arrow is touching the part, as you see in the first image the arrow’s center is inside the part but i want it so the arrow’s endpoint is in the center, like the second image. Sorry if my wording wasn’t so great.

1 Like

So to make the end of the arrow touch the endpoint of the part, you can calculate the offset vector based on the length of the arrow and the size of the part, and adjust it by the position of the part. I will try it in studio could you send the model?

Can you show me a your full script of your arrow? So I might know it what to do

this is the full function that i use to update the arrow for positioning

function updateArrow(mag) -- position / rotate arrow
	local mag = mag or  math.clamp(((mouse.Hit.Position - startpos).Magnitude) / 2, 0, 20)
	local arrow = part:FindFirstChild("Arrow")
	arrow.Size = Vector3.new(0.09,mag,3.6)
	local pos = part.Position
	local pos2 = mouse.Hit.Position
	arrow.CFrame = CFrame.new(pos, pos2) * CFrame.Angles(math.rad(0), math.rad(90), math.rad(90))
end

the arrow is just set at the parts position initially but i run this function every mouse movement

if you just send me the math ill input it and see if it works, ive tried this but I wouldnt work maybe i did something wrong

I’ve rescripted it in studio and came to a conclusion :

local part = workspace.Part

local mouse = game:GetService("Players").LocalPlayer:GetMouse()

local arrow = part:FindFirstChild("Arrow")

local arrowLength = arrow.Size.Y -- get the length of the arrow

local partSize = part.Size -- get the size of the part

-- Calculate the offset vector based on the size of the part, the length of the arrow, and the orientation of the arrow

local offset = Vector3.new(0, partSize.Y/2 + arrowLength/2, 0)

offset = offset * arrow.CFrame:vectorToWorldSpace(Vector3.new(1, 0, 0))

-- Adjust the position of the arrow by the position of the part

local pos = part.Position + offset + part.CFrame:vectorToWorldSpace(Vector3.new(0, 0, -partSize.Z/2))

local pos2 = part.Position + partSize/2 -- use the position of the part as pos2

arrow.CFrame = CFrame.new(pos, pos2) * CFrame.Angles(math.rad(0), math.rad(90), math.rad(90)) -- construct cframe and rotate

This will adjust the offset vector based on the orientation of the arrow, and also adjust the position of the arrow by the position of the part, so that the end of the arrow touches the endpoint of the part.

Looks like this in game (with the game ran)

image

Mark this as solution if it worked.

I inputed everything and changed the pos2 to mouse.Hit.Position and made the Y value of pos 0 (I want it to be on the ground) and now im getting this:
image

Maybe its something to do with my arrow model, heres what i have now:

arrow.Size = Vector3.new(0.09,mag,3.6)
local arrowLength = arrow.Size.Y
local offset = Vector3.new(0, partSize.Y/2 + arrowLength/2, 0)

offset = offset * arrow.CFrame:vectorToWorldSpace(Vector3.new(1, 0, 0))

-- Adjust the position of the arrow by the position of the part

local pos = part.Position + offset + part.CFrame:vectorToWorldSpace(Vector3.new(0, 0, -partSize.Z/2))

local pos2 = part.Position + partSize/2 -- use the position of the part as pos2
pos = pos - Vector3.new(0,pos.Y,0)
arrow.CFrame = CFrame.new(pos, mouse.Hit.Position) * CFrame.Angles(math.rad(0), math.rad(90), math.rad(90)) -- construct cframe and rotate

Strange, it worked for me so it might be your arrow, is it a mesh?

Mine simply made this

local part = workspace.Part
local mouse = game.Players.LocalPlayer:GetMouse()
local arrow = part:FindFirstChild("Arrow")
local startpos = part.CFrame.p
local targetpos = mouse.Hit.p
arrow.CFrame = CFrame.new(startpos,targetpos) * CFrame.new(0,0,-7)

Proof :
RobloxScreenShot20221222_074320748

strange lol…

try adding these lines

local partSize = part.Size

local endPoint = part.Position + part.CFrame:vectorToWorldSpace(Vector3.new(0, 0, partSize.Z/2))

arrow.CFrame = CFrame.new(arrow.Position, endPoint)

Answer :

local part = workspace.Part
local mouse = game.Players.LocalPlayer:GetMouse()
local arrow = part:FindFirstChild("Arrow")
local partSize = part.Size

local endPoint = part.Position + part.CFrame:vectorToWorldSpace(Vector3.new(0, 0, partSize.Z/2))

arrow.CFrame = CFrame.new(arrow.Position, endPoint)

even worse, im clueless since it worked for me

I tried this but i cant get my arrow to rotate properly it seems

arrow.CFrame = CFrame.new(part.Position, mouse.Hit.Position) * CFrame.Angles(math.rad(0), math.rad(180), math.rad(90)) * CFrame.new(0,0,-7)-- construct cframe and rotate

Maybe if I could just get your arrow model that would be best

try this i guess

arrow.CFrame = CFrame.new(startpos,targetpos) * CFrame.new(0,0,-7) * CFrame.Angles(math.rad(0), math.rad(0), math.rad(90))

Sorry i was AFK, I am remaking it for you give me a sec