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

Animation: My model plays the animation but it doesn't move from it's position?

Asked by 5 years ago
Edited 5 years ago

I created a model called Golem and I rigged it correctly (I'm pretty sure) and I made an animation for it which is just a basic walking animation. I am using most of the scripts and values that can be found in the AI Enemy model in the tool box. I modified the follow script so that it played my animation when it moved. The issue is that the Golem doesn't move. I know for a fact that it is running through he line of code that tells it to move with no error since no errors pop up and because it runs the next lines. I did a compared this version of the Golem to an earlier one I made that moves without the animation (and the earlier version does move, it just doesn't have the animation which means that the animation is causing the problem) and the only difference I found was that the Golem that moved had it's Root Part property set to Torso and the one that doesn't move yet plays the animation has it's Root Part property set to HumanoidRootPart (The Root Part property is in the Humanoid object in the Model). Here is my code that tells it to follow:

`local larm = script.Parent:FindFirstChild("Left Arm")
local rarm = script.Parent:FindFirstChild("Right Arm")
local isplaying = false
local GolemWalkAnim = game.Workspace.GolemWalk
local animTrack = script.Parent.Enemy:LoadAnimation(GolemWalkAnim)

function findNearestTorso(pos)
    local list = game.Workspace:children()
    local torso = nil
    local dist = 20
    local temp = nil
    local human = nil
    local temp2 = nil
    for x = 1, #list do
        temp2 = list[x]
        if (temp2.className == "Model") and (temp2 ~= script.Parent) then
            temp = temp2:findFirstChild("Torso")
            human = temp2:findFirstChild("Humanoid")
            if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
                if (temp.Position - pos).magnitude < dist then
                    torso = temp
                    dist = (temp.Position - pos).magnitude
                end
            end
        end
    end
    return torso
end

function walk()
if isplaying == false then
        animTrack:Play()
        isplaying = true
        AnimationCooldown()
    end
end

function AnimationCooldown()
    wait(1.1)
    isplaying = false
end

while true do
    wait(0.1)
    local target = findNearestTorso(script.Parent.Torso.Position)
    if target ~= nil then
        script.Parent.Enemy:MoveTo(target.Position)
        animTrack:Play()
        walk()
    end
end

I copied this code and put it into the follow script in the other Golem (the one without the animation but it moves) and it still moved but it just didn't play the animation (I'm guessing it didn't play the animation because it wasn't rigged. It also doesn't have a HumanoidRootPart) So my final question is, what am I doing wrong? My goal is to make an enemy named Golem that follows the closest player and plays a walking animation while its following that player. Sorry for the long post but I wanted to be as detailed as possible.

0
Please put your code in a code block, i'm having trouble reading it. NinjaManChase 226 — 5y
0
put code in the lines after u press the lua button LiLFriks 39 — 5y
0
Ok I put it in lines GamerX2O 0 — 5y
0
if it doesn't have a root part and is rigged correctly you could use a AnimationController the8bitdude11 358 — 5y
0
^ and load the animation into the controller the8bitdude11 358 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

remove the ` in the very first line of the script in the beginning

Ad

Answer this question