Hi guys, how would i go about finding out if a character is idling or not? GetState() doesn't return an "Idle" state when a player is stationary. It returns "RunningNoPhysics" back to me, which i cannot use because while running, Getstate() will return both "RunningNoPhysics" and "Running" in intervals. There are 2 ways I've thought about.
1) Use 2 variables to find out the distance between the new and old position of the humanoidRootPart, on all 3 axis (X,Y,Z) so i will have a total of 6 variables, 1 old and 1 new for each axis. After that, grab the difference and make sure all 3 differences = 0 (Means not moving).
2) While running, i realised GetState() will only return between 200-300 "RunningNoPhysics". I will look more >300 "RunningNoPhysics" and decide if the player is moving or not.
I should also place the above 2 suggestions in a "spawn (function()end)" to keep the calculation constantly updated. Are there any better methods to deal with this? I can't seem to get "humanoid.Running:connect()" working. It got skipped even when I'm running..
There is an event for players called Player.Idled()
Another method:
game.Workspace.Player.Humanoid.Running:connect(function(speed) if speed > 0 then print("Player is running") -- player is walking else print("Player has stopped") -- player is idle end end)
hmm, have a script that will detect every possible thing that can make a player move, like ckeck if the player is holding w, a, s or d, spacebar and have that connect to a module. Also every single code u make that will move the character like press e near a bed to sleep should connect to a module. The module should have the following code:
local animator = {} local humanoidRoot = script.Parent.HumanoidRootPart animator.Moving = function() local pos = humanoidRoot.Position wait() while pos ~= humanoidRoot.Position do wait() pos = humanoidRoot.Position end wait(**however much time u wanna wait for the animation**) script.Parent.Humanoid:LoadAnimation(animation):Play() end return animator
Make sure the animation is an idle animation, idk much about animations but I think their own idle animation will play over your animation otherwise, but dont have it more than idle because otherwise it might play over their walking animation. And don't forget to put the module script in starter character scripts.
P.S. I haven't tried to do this with a player but im pretty sure this will work ;)