How to make attachment's main axis point toward's player's face?

I’m trying to make a loose-item dragging system in my sandbox game using Roblox’s new DragDetectors. None of the drag style presents quite match what I wanted, so I’ve been trying to customize the TranslateViewPlane drag style. One thing that I think improves the drag movement was to add an AlignPosition that constantly points the part towards the player’s FaceFrontAttachment by setting it as the alignment’s Attachment1. To make it even more intuitive, I wanted the Attachment0’s primary axis to point towards the player’s face, to prevent the part from snapping around when the player first clicks it. However, I’m not very good understanding CFrames or angles, and I can’t get the attachment to align correctly.

local part = script.Parent
local clicker = part.DragDetector
local thing = part.AlignOrientation
local att = part.Attachment

clicker.DragStart:Connect(function(plr, ray, viewFrame, hitFrame, BP, other, key)
	part.Massless = true
	
	local newFrame = CFrame.lookAt(hitFrame.Position, plr.Character.Head.FaceFrontAttachment.WorldPosition)
	local x, y, z = newFrame:ToOrientation()
	
	att.Axis = Vector3.new(x, y, z)
	att.WorldPosition = hitFrame.Position
	thing.Attachment1 = plr.Character.Head.FaceFrontAttachment
end)

clicker.DragEnd:Connect(function(plr)
	part.Massless = false
	thing.Attachment1 = nil
end)

I’ve tried many different methods of trying to get the attachment’s axis to point towards the player, this is just one of those methods, and it doesn’t really work.

Solved

clicker.DragStart:Connect(function(plr, ray, viewFrame, hitFrame, BP, other, key)
	local goal = plr.Character.Head.FaceFrontAttachment
	
	local direction = CFrame.lookAt(hitFrame.p, goal.WorldPosition) * CFrame.new(Vector3.zero, Vector3.new(-90, 0, 0))

	att.WorldCFrame = direction
	thing.Attachment1 = goal
	part.Massless = true
end)

I had to multiply the LookAt CFrame’s orientation by -90 z

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