#Pet Idle Animation Issues

2 messages · Page 1 of 1 (latest)

whole yew
#

I'm using AI to help me learn rn. I'm just trying to make some pet system and want an idle animation for the pet.

local runService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local luffyModel = workspace:WaitForChild("LuffyModel")

if not luffyModel.PrimaryPart then
    luffyModel.PrimaryPart = luffyModel:FindFirstChild("Torso") or luffyModel:FindFirstChild("HumanoidRootPart")
end

local animator = humanoid:FindFirstChildOfClass("Animator") or Instance.new("Animator", humanoid)

local idleAnimationId = "rbxassetid://71991750694124"
local idleAnimation = Instance.new("Animation")
idleAnimation.AnimationId = idleAnimationId

local idleAnimationTrack = animator:LoadAnimation(idleAnimation)
idleAnimationTrack.Priority = Enum.AnimationPriority.Action
idleAnimationTrack:Play()

local circle = math.pi * 2
local bounceAmplitude = 1
local bounceFrequency = 2
local heightOffset = 2

local function getPosition(angle, radius)
    local x = math.cos(angle) * radius
    local z = math.sin(angle) * radius
    return x, z
end

runService.RenderStepped:Connect(function()
    if character and character.PrimaryPart then
        local velocity = character.HumanoidRootPart.Velocity
        local speed = velocity.Magnitude
        local direction = velocity.Unit

        local radius = 4 + (speed * 0.1)
        local angle = tick() * 0.5
        local x, z = getPosition(angle, radius)

        local _, characterSize = character:GetBoundingBox()
        local _, luffySize = luffyModel:GetBoundingBox()

        local offsetY = -characterSize.Y / 2 + luffySize.Y / 2 + heightOffset
        local bounce = math.sin(tick() * bounceFrequency) * bounceAmplitude

        luffyModel:SetPrimaryPartCFrame(luffyModel.PrimaryPart.CFrame:Lerp(character.PrimaryPart.CFrame * CFrame.new(x, offsetY + bounce, z), 0.1))
    end
end)
#

I don't know much so help would be much appreciated. I'm using a humanoid model and I'm not sure if its the script or a problem with the model