Hey there! I am using AlignPosition
and AlignOrientation
to make a virtual pet follow you around. I noticed a glitch where if you get the pet stuck and then jump, you get flung. Here is my code:
asset:SetPrimaryPartCFrame(player.Character.PrimaryPart.CFrame + position)
local attachment0 = Instance.new("Attachment")
attachment0.Parent = asset.PrimaryPart
local attachment1 = Instance.new("Attachment")
attachment1.Position = position -- position is a Vector3 Value
attachment1.Parent = player.Character.PrimaryPart
local alignPosition = Instance.new("AlignPosition")
alignPosition.Attachment0 = attachment0
alignPosition.Attachment1 = attachment1
alignPosition.RigidityEnabled = false
alignPosition.Responsiveness = 5
alignPosition.Parent = asset
local alignOrientation = Instance.new("AlignOrientation")
alignOrientation.Attachment0 = attachment0
alignOrientation.Attachment1 = attachment1
alignOrientation.RigidityEnabled = true
alignOrientation.Parent = asset
for i, v in pairs(asset:GetChildren()) do
if v:IsA("BasePart") then
v.Anchored = false
end
end
asset.Parent = player.Character
Any suggestions? Thanks!
Just a tip, to format your code better you can type it like this:
```lua
print(“Code here!”)```