When moving sideways in shiftlock move direction becomes Vector3.new()

I’m using Humanoid.MoveDirection to determain when the character has stopped moving to stop a custom walk animation, when moving sideways in shift lock the change between left and right causes MoveDirection to become 0,0,0 it only makes sense it would but since I’m checking for when its 0,0,0 to stop the walk animation the walk animation stops when it shouldnt because technically the character is still moving around, that leaves an ugly stutter as the animation stops and resumes when it should just keep on playing, what should I do?
That’s the code I’m looking to improve:

the scrapped line was used as a workaround but i figured out that it would cause the character to have the walk anim to still play if the right keys are pressed

Hey! If you are trying to check if a player is moving at all, no matter the direction you can get the Magnitude of the MoveDirection like this:

		RunService.Heartbeat:Connect(function(step)
			print(player.Character.Humanoid.MoveDirection.magnitude)

		end)

It will return 1 of it’s moving, and 0 if the player is standing still. Then an extra thing you can add is the fadeTime parameter on the :Stop() to prevent the animation from giving a “snapping effect” when you’re switching between them. The parameter gives a fade animation between the current animation, and the one you’re switching to. It can also be used in :Play() animation.

Example:

WalkTrack:Stop(1)
RunTrack:Stop(1)

Wouldnt the magnitude be 0 if it is 0,0,0 though?

Are you saying that if you move to the right/left using shiftlock it’s (0, 0, 0)?

Correct the code I sent executes

I can 100% guarantee you that if you’re moving at all, you won’t get a moveDirection of (0, 0, 0). This is probably being caused by another part of your code then

You can try yourself, check in renderstepped when MoveDirection is 0,0,0 it will trigger if you do this

Try adding fade times to your play and stop functions on the animations, and send a video of what that looks like. (I didn’t understand your problem, but read it over and do now).


Doesnt seem to change anything

How did you add them? Because I didn’t notice any fade effect on the animations

I put a 1 inside the brackets of :Stop()

1 Like

One of the solutions I thought of was having two checks, at separate times. Basically what this does is first checks is the player has stopped, then it confirms it’s a permanent stop and they aren’t just side moving.

			local timeCheck = 0.1
			
			if player.Character.Humanoid.MoveDirection.magnitude == 0 then
				local nt = 0
				
				while (nt < timeCheck) do
					if player.Character.Humanoid.MoveDirection.magnitude ~= 0 then
						--player moved
						return
							
					end
					nt = nt + RunService.Heartbeat:Wait()
					
				end
				--Confirmation player has not moved
				print("not moving")
				
			end

Video:

1 Like

Thank you very much that worked :smiley:

1 Like

Yay :partying_face:

1 Like