Right. Im creating a animation script for a RPG enemy, (and I know it is not correct), and that I cant figure out what I need to find out the speed/or at least how to tell whether the enemy is moving, so when he is moving he "runs" and when he is not, he "Stands". If you use a free model script, the animation for a RPG enemy works fine, in solo mode. However when going to normal (multiplayer) mode it decides to not work. idk if this is to do with servers/clients etc, because I don't understand them. Is there something else I need to do? :
function onRunning() if isSeated then return end if script.Parent.Torso.Velocity > (0,0,0) then -- A single value wont work pose = "Running" else pose = "Standing" end end
Thanks ~Bubs
If you're using the Running event, you can receive the speed of the character by its argument.
Humanoid.Running:connect(function (speed) if speed > 20 then print("Wow, you're fast!") else print("Wow, you're slow.") end end)
You could also calculate the speed by using the HumanoidRootPart velocity's "x" and "z" components with Pythagorean Theorem.
HRP = script.Parent.HumanoidRootPart function PythagoreanTheorem(a, b) local solution = math.sqrt(math.pow(a, 2) + math.pow(b, 2)) return solution end function Example() if PythagoreanTheorem(HRP.Velocity.x, HRP.Velocity.z) > 20 then print("Wow, you're fast!") else print("Wow, you're slow.") end end
Why not use the Torso's velocity components? Because, in my perspective, animations can make the velocity of the torso go faster.
If your enemy has a Humanoid in it, you can use the Running
event of the Humanoid to determine whether they are running or not.
The running event has a single number parameter, speed
. This variable tells you how fast the humanoid is running when the event is triggered.
The running event is also useful to you because this event is triggered when the player stops moving too, where the speed parameter becomes 0.
For your script above, you can do the following to accomplish what you're doing:
script.Parent.Humanoid.Running:connect(function(speed) --Change the path so it points to the humanoid of the enemy. if isSeated then return end --I suppose you need this so I kept it in just in case. if speed > 0 then --If the enemy is running then set the pose. pose = "Running" else pose = "Standing" end end)