Issues with Converting CFrame To Attachment's Object Space

My goal is to convert the Y cframe orientation in world space to an attachment’s object space so that no matter where the attachment’s parent is looking, it will always point towards required direction.

local x,y,z = CFrame.Angles(0,YOrientation,0):ToObjectSpace(rope.Hook.Attachment.CFrame):ToOrientation()

rope.Hook.Attachment.CFrame = CFrame.Angles(0,y,0)

Where YOrientation is camera’s cframe Y orientation in radians converted via the same method

local x,y,z = game.Workspace.CurrentCamera.CFrame:ToOrientation()

The issue is that it doesn’t seem to point into the direction it’s supposed to.

Thank you for your attention.

Try this:

attachmentWorldCFrame = attachment.Parent.CFrame * attachment.CFrame
--To solve for attachment.CFrame, apply parent inverse left sides of the equation
attachment.Parent.CFrame:Inverse() * attachmentWorldCFrame =  attachment.CFrame
--rearrange
attachment.CFrame = attachment.Parent.CFrame:Inverse() * attachmentWorldCFrame 

--Apply desired World CFrame
local x,y,z = game.Workspace.CurrentCamera.CFrame:ToOrientation()
local rotationCF = attachment.Parent.CFrame:Inverse() * CFrame.fromOrientation(0,y,0)
attachment.CFrame = rotationCF.Rotation + attachment.CFrame.Position --Maintain original attachment position, use new rotation CFrame

There is also the attachment.WorldCFrame property which could also be used.

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