What do you want to achieve? Keep it simple and clear!
I’m trying to make a script that plays a run animation whenever an NPC is moving
What is the issue? Include screenshots / videos if possible!
Whenever the NPC is touching the ground and the animation is playing, it sort of interacts weirdly with the ground being moved occasionally and shaking weirdly. This happens even if I’m not manually moving the NPC in any way. This might not help a lot, but I also noticed that if I try moving the NPC with MoveTo without any animation playing, it looks like its getting stuck on something and stops moving altogether after a few steps but if I look closely I can see it shaking.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve made sure that no animations are playing at the same time or overriding the run animation. I also checked with different animations, so this isn’t and issue specifically with the animation I’m using. I’ve been trying to find a fix on dev forum.
I’m handling everything on a server script
This is what I’m doing to figure out whether the NPC is moving or not:
if math.floor(HumanoidRootPart.Velocity.Magnitude)>0 then
--Is moving
else
--Is not moving
end
This is what it looks like when I’m not moving the NPC:
For when I am moving it, its about the same thing but with less involuntary movement and visible shakiness
Using Humanoid.MoveDirection.Magnitude > 0 instead of math.floor(HumanoidRootPart.Velocity.Magnitude)>0 doesn’t work altogether because MoveDirection doesn’t work with NPCs.
I’m using math.floor() because I saw a devforum post saying that if the HumanoidRootPart is slightly rotated the velocity is above 0 and it didn’t seem to break the script.
The main issue I have is with the way the NPC twitches and also gets moved randomly when the animation is playing.
Nothing from the script and no invisible objects, just what you see. The NPC is an R6 model. I’ve tried taking the NPC into a different game file to make sure no other scripts could be interfering and there was the same outcome.
Also I think I mentioned this in the original post, but if there is no animation playing when the NPC tries moving through MoveTo it can’t really move, almost as if its getting stuck in something. Like it takes a few steps and then stops, but still visibly twitching. I already made sure the MoveTo isn’t expiring from the 8 second timer.
The HumanoidRootPart, or HRP for short, shouldn’t be twitching or anything if the NPC is not moving. One thing that comes to mind is AssemblyLinearVelocity which is the newer Velocity basically. Velocity was depreciated.
If you set HRP.Transparency to 0 it might help you see what is happening as well.
I’ve switched the Velocity part to AssemblyLinearVelocity earlier, it continued detecting whether the NPC is moving or not correctly. So that works good
This is what I can see if I put the HRP.Transparency to 0 (Note that this is with me playing the animation manually, without moving the NPC or trying to detect if the NPC is moving or not):
The movement that you see is also only happening when I’m playing the animation