Attachment won't point towards player's lookVector

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

1 Like

Isn’t it WorldCFrame?

try this

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

same problem and unless I dont add

CFrame.lookAt(attachment.WorldCFrame.Position, playerLookPos.Position)

.Position at the end it will error (Vector3 expected, got CFrame)

yeah i forgot to add the position is the behavior the same as with your last code though?

Yeah pretty much, it just does not want to point at player look Pos

Try this

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

Maybe this would work.

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.

https://devforum.roblox.com/t/rotating-an-attachment-to-look-at-a-position/1876901