How to fix alignposition not moving part?

I am attempting to switch from body position to the not deprecated align position but am having issue. The part that has the align position is going far away from the humanoid root part even though if use body position the pet is next to the humanoidrootpart just fine. I also noticed if I use align position the custom character im using has its aniamtions interuppted and the character becomes laggy.

here is the code

local a0 = Instance.new("Attachment")
        a0.Parent = PetMesh
        a0.Position = PetMesh.Position
        
        local a1 = Instance.new("Attachment")
        a1.Parent = self.Character.HumanoidRootPart
    
        local alignPosition = Instance.new("AlignPosition")
        alignPosition.Parent = PetMesh
        alignPosition.ApplyAtCenterOfMass = true
        alignPosition.RigidityEnabled = true
        alignPosition.ReactionForceEnabled = false
        alignPosition.Attachment0 = a0
        alignPosition.Attachment1 = a1

        local function UpdatePetPosition()
            local newPos = (self.Character.HumanoidRootPart.CFrame * CFrame.new(MathUtil.GetPointOnCircle(.5, 360/1))).Position - Vector3.new(0, self.Character.HumanoidRootPart.Size.Y / 2, 0) + Vector3.new(0, self.Character.Headpiece.Size.Y, 0)
            a1.Position = newPos
        end

        RunService:BindToRenderStep("UpdatePetPosition", 1, UpdatePetPosition)
2 Likes

Seems like you’re trying to place the Attachment at the same position as a MeshPart…

The Position property of Attachments actually describes the position of the attachment relative to the parent. So if you want the attachment to be 3 studs to the right of the parent part, you’d set Position to (3, 0, 0), or WorldPosition to Part.CFrame * Vector3.new(3, 0, 0). WorldPosition is the “real position” of the attachment.

This is such a confusing decision and I can’t get why Roblox decided to do it like that. Should have just called Position “RelativePosition” instead. But that’s what we’ve got to work with and once you know it’s not so bad ¯\(ツ)/¯ </rant>

1 Like

so after remove the line of code with .Position it still didnt fix it

wait, how would I convert from relative to world position in the UpdatePetPosition function so I can assign the attachment position correctly?

Attachments have two properties related to position: Position and WorldPosition. WorldPosition is like the Position property of Parts. So if you do attachment.WorldPosition = part.Position, the Attachment would be placed at the same position as the Part, no matter which Part the Attachment is a child of. If you set the Position of an attachment to e.g. (3, 0, 0), it will be placed 3 studs to the right of the Part that it’s a child of.

So instead of a0.Position = PetMesh.Position, you’d do a0.WorldPosition = PetMesh.Position

2 Likes