Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i change and add default animation for an npc?

Asked by 1 year ago
Edited 1 year ago

I dont want to copy the Animate localscript from a player

I've done sum research on google and couldnt find it out. Im using

if math.floor(npc.HumanoidRootPart.Velocity.Magnitude)>0 then

but animation like default r15 running actually affect the HumanoidRootPart velocity. Others like idle or anything that doesnt move the root part works.

This is what does the code looks like

local animation = {
        idle = npc.Idle,
        run = npc.Run,
        atk = npc.Attack
}


local IdleTrack = npc.Humanoid:LoadAnimation(animation.idle)
local AttackTrack = npc.Humanoid:LoadAnimation(animation.atk)
local RunTrack = npc.Humanoid:LoadAnimation(animation.run)

local animtable = {
    ['idle'] = IdleTrack,
    ['run'] = RunTrack,
    ['atk'] = AttackTrack
}

local animstring = 'idle'

while wait() do
    if not animtable[animstring].isPlaying then
        for i,v in pairs(animtable) do
            if not i == animstring then
                animtable[i]:Stop()
            end
        end

        animtable[animstring]:Play()
        print(animtable[animstring])
    end

    npc.Humanoid:MoveTo(baseunit.Position + Vector3.new(8,0,0))

    for i, entity in pairs(game.ReplicatedStorage.UnitFolder:GetChildren()) do
        if math.floor(npc.HumanoidRootPart.Velocity.Magnitude)>0 then
            animstring = 'run'
        elseif game.Workspace:FindFirstChild(entity.Name) then
            local relativePos = npc.Hitbox.CFrame:pointToObjectSpace(entity.HumanoidRootPart.Position)
            if math.abs(relativePos.X) <= npc.Hitbox.Size.X * 0.8 * 0.5 and math.abs(relativePos.Z) <= npc.Hitbox.Size.Z * 0.8 * 0.5 then
                print(tostring(entity.Name).." is inside")
                animstring = 'atk'
                onHit(1.2)
                task.wait(1.5)
            end
        else
            animstring = 'idle'
            IdleTrack:Play()
        end
    end
end

1 answer

Log in to vote
0
Answered by
enes223 327 Moderation Voter
1 year ago

hey you! have you ever heard of enes? if you are in trouble, better call enes!

Ad

Answer this question