So I have a attachment inside of humanoidRootPart and a vectorForce. And I want the attachment to always point where the player is looking so that the vectorForce can do it’s job and push the player where he is looking.
function updateLookPos(playerLookPos)
local attachment = humRoot:FindFirstChild("Attachment")
if attachment then
attachment.WorldOrientation = playerLookPos.Position
end
end
while wait(0.1) do
local playerLookPos = head.CFrame + head.CFrame.LookVector
updateLookPos(playerLookPos)
end
(I create the attachment and vectorForce in another function.
And as you can see, the attachment just wont point to where I am looking, and yes I did try to set the WorldPosition of the attachment to the HumanoidRootPart but still no luck
function updateLookPos(playerLookPos)
local attachment = humRoot:FindFirstChild("Attachment")
if attachment then
attachment.WorldCFrame = CFrame.lookAt(attachment.WorldCFrame.Position, playerLookPos)
end
end
while wait(0.1) do
local playerLookPos = head.CFrame + head.CFrame.LookVector
updateLookPos(playerLookPos)
end
function updateLookPos(playerLookPos)
local attachment = humRoot:FindFirstChild("Attachment")
if attachment then
attachment.WorldCFrame = CFrame.lookAt(attachment.WorldCFrame.Position, playerLookPos)
end
end
while wait(0.1) do
local playerLookPos = head.Position + head.CFrame.LookVector*1000
updateLookPos(playerLookPos)
end
local function updateLookPos(target)
if attachment then
local attachment = humRoot:FindFirstChild("Attachment")
local attachmentPosWorld = part.CFrame:PositionToWorldSpace(attachment.Position)
local attachmentCFWorld = CFrame.lookAt(attachmentPosWorld, target)
attachment.WorldCFrame = attachmentCFWorld
--return part.CFrame:ToObjectSpace(attachmentCFWorld)
-- note: if you are concerned about losing position accuracy due to floating point error accumulationg you could do something like:
--[[
local attachmentCFLocal = part.CFrame:ToObjectSpace(attachmentCFWorld)
return attachmentCFLocal - attachmentCFLocal.Position + attachment.Position
]]
end
end
while wait(0.1) do
local playerLookPos = head.CFrame + head.CFrame.LookVector * 10
updateLookPos(playerLookPos)
end
I found this code on another devforum page and modified it a bit to try and meet your desires.