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)
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>
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