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.
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?
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.
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:
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
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)
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)