I have 2 attachments that make up a HingeContraint, and I want them to be oriented towards the player once something happens. I’ve tried multiple methods, but the attachment either doesn’t move, or get’s snapped to a strange position. How can I make these look at the player?
Do you mind explaining what methods you tried? I may be able to help if I can better understand the issue you’re facing.
I’ve tried using CFrame.lootAt(). That one snapped it to a weird position. I also tried using just the .Orientation property. That one didn’t rotate at all. With that one, I just tried setting the Z axis to match the orientation of the player’s root part. I only want it to follow on that axis
Attachments are a bit weird, their positions and orientations are relative to their parent’s. You may need to use WorldOrientation (or WorldCFrame, depending on your set up) along side CFrame.lookAt() to achieve the result you’re looking for.
Is there a way to make lookAt() only apply to the Z axis?
You could take the result of the lookAt and only use the Z result if that’s what you mean. Do you mind sharing the code you are trying to use or tried to use before?
local Attachment0 = Tree.Stump:FindFirstChildWhichIsA("Attachment")
local Attachment1 = Tree.TrunkBottom:FindFirstChildWhichIsA("Attachment")
local Root = Player.Character.HumanoidRootPart
local LookVector = Root.CFrame.LookVector
Attachment0.WorldCFrame = CFrame.lookAt(Attachment0.WorldPosition,Root.Position)
Attachment1.WorldCFrame = CFrame.lookAt(Attachment1.WorldPosition,Root.Position)
This is what I’ve got so far. It’s not the full code, just the relevant part
What happens when you try to use this code?
It’s activated with a click. . First click rotates it, and any other click afterwards does nothing. I have confirmed the code continues to run after the first click, so it’s not a ClickDetector issue.