I have a pet system that uses align position and align orientation. My issue is that the pets are super jittery. Here is a video of it.
Here is the code that sets the target position for the two body movers.
targetCF = Player.Character.HumanoidRootPart.CFrame * CFrame.new(Vector3.new(xOffset,0,3*math.floor(count))) -- * CFrame.Angles(0, 0, 0)
local TargetPos = targetCF.Position
local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = {Player.Character.PetFolder}
RayParams.FilterType = Enum.RaycastFilterType.Exclude
RayParams.RespectCanCollide = true
local PetPosition, PetHeight = petModel:GetBoundingBox()
PetPosition = PetPosition.Position
PetHeight = PetHeight.Y
local RayCast = workspace:Raycast(Vector3.new(TargetPos.X, Player.Character.Head.Position.Y, TargetPos.Z), Vector3.new(0,-20,0), RayParams)
if RayCast and RayCast.Position then
local y = RayCast.Position.Y + (PetHeight/2) - (PetPosition.Y - petModel.Center.Position.Y)
targetCF = CFrame.new(Vector3.new(TargetPos.X, y, TargetPos.Z)) * targetCF.Rotation
end
if Player.Character.HumanoidRootPart.AssemblyLinearVelocity.Magnitude > .7 then
targetCF = CFrame.new(Vector3.new(TargetPos.X, targetCF.Position.Y + math.clamp(math.sin(tick() * 20),-.2,1), TargetPos.Z)) * targetCF.Rotation * CFrame.Angles(-math.rad(MaxRotation * math.sin(tick() * 15)), 0, -math.rad(MaxRotation * math.sin(tick() * 10)))
end
petModel:WaitForChild("Center").AlignPosition.Position = targetCF.Position
petModel.Center.AlignOrientation.CFrame = targetCF
I have tried using a lerp instead of body movers and still run into the same issues. Here are the settings for the body movers
local AlignOrientation = Instance.new("AlignOrientation", Clone.Center)
AlignOrientation.Attachment0 = Clone.Center.Attachment
AlignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment
AlignOrientation.Responsiveness = 25
AlignOrientation.MaxTorque = 25000
local AlignPosition = Instance.new("AlignPosition", Clone.Center)
AlignPosition.Mode = Enum.PositionAlignmentMode.OneAttachment
AlignPosition.MaxForce = 25000
AlignPosition.Responsiveness = 25
AlignPosition.MaxVelocity = 1000
AlignPosition.ApplyAtCenterOfMass = true
AlignPosition.Attachment0 = Clone.Center.Attachment
AlignPosition.Position = Player.Character.PrimaryPart.Position
If anyone has any ideas, please let me know.