CFrame.new(Position,LookAt) Rotation Bug

I have two attachments in the weapon. The arms have a pivot point that attaches to the attachments, and points to the camera.
Why do my arms rotate like this?

return function(GunModel:Model)
	local LeftArmAttachment = GunModel:FindFirstChild("LeftHand",true)
	local RightArmAttachment = GunModel:FindFirstChild("RightHand",true)
	
	local LeftArmAttachmentPosition = LeftArmAttachment.WorldCFrame.Position
	local RightArmAttachmentPosition = RightArmAttachment.WorldCFrame.Position
	
	LeftArm:PivotTo(
		CFrame.new(
			LeftArmAttachmentPosition,
			(Camera.CFrame*LeftArmOffset).Position
		)
	)
	RightArm:PivotTo(
		CFrame.new(
			RightArmAttachmentPosition,
			(Camera.CFrame*RightArmOffset).Position
		)
	)
end

what’s wrong with my math? Ive been tearing my hair out over this.

1 Like

Try using CFrame.lookAt as it allows you to specify an up vector argument which should fix it in this case. I believe it would be your attachment’s WorldCFrame’s UpVector

local leftArmUp = leftArmAttachment.WorldCFrame.UpVector

leftArm:PivotTo(CFrame.lookAt(leftArmAttachmentPosition, (camera.CFrame * leftArmOffset).Position, leftArmUp)

Behaviour should be the same as CFrame.new(position, lookAt)

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.