How do i make Realistic Walking/Running?

So uh. I’m really excited about this stuff. However for some reason it does not replicate for other players. Is there any way to make it replicate for other players? if so, can you tell me what you did to make it replicate for other players? I would greatly appreciate it.

1 Like

you might have to set your animation priority to action and if you have a custom walk animation maybe set the priority to movement.

1 Like

He already found the solution.

2 Likes

you need to set the animation weight to 0.001 when you want it to stop
anything lower causes the animations to stop replicating for some reason

This still replicates oddly. I have been experimenting with the OP’s script, and found a more performant and cleaner looking method. Instead of constantly looping every animation at once and adjusting the weight to 0 to stop the animation, I opted to instead play each animation whenever it’s weight is adjusted, but only if it isn’t currently playing. Here’s the adjusted script:

local function StopAllAnims()
	for i,v in pairs(anim) do
		v:Stop()
	end
end


runService.RenderStepped:Connect(function()
	local movedir = Character.PrimaryPart.CFrame:vectorToObjectSpace(Humanoid.MoveDirection)
	local currentstate = Humanoid:GetState()
	X = movedir.X
	Z = movedir.Z
	local distZ,distZMin = ((Character.PrimaryPart.CFrame.LookVector * 5) - Vector3.new(0,0,Z)).Magnitude,((Character.PrimaryPart.CFrame.LookVector * -5) - Vector3.new(0,0,Z)).Magnitude
	--print("X = "..movedir.X.." Z = "..movedir.Z)
	if currentstate == Enum.HumanoidStateType.Jumping then
		StopAllAnims()
	elseif currentstate == Enum.HumanoidStateType.Freefall then
		StopAllAnims()
	elseif movedir.Magnitude == 0 then
		StopAllAnims()
	else
		if Z == 0 then
			anim["backwalk"]:Stop()
			anim["frontwalk"]:Stop()
			anim["frontrun"]:Stop()
		elseif Z < 0 then
			anim["backwalk"]:Stop()
			if not anim["frontrun"].IsPlaying then
				anim["frontrun"]:Play()
			end
			anim["frontrun"]:AdjustWeight(Z*-1.1)
			if not anim["frontrun"].IsPlaying then
				anim["frontwalk"]:Play()
			end
			anim["frontwalk"]:AdjustWeight(1-((Humanoid.WalkSpeed/10)-1))
		elseif Z > 0 then
			if not anim["backwalk"].IsPlaying then
				anim["backwalk"]:Play()
			end
			anim["backwalk"]:AdjustWeight(Z*1.1)
			anim["frontrun"]:Stop()
			anim["frontwalk"]:Stop()
		end
		if X == 0 then
			anim["rightwalk"]: Stop()
			anim["leftwalk"]: Stop()
		elseif X < 0 and not UIS:IsKeyDown(Enum.KeyCode.W) and not UIS:IsKeyDown(Enum.KeyCode.S) then
			if not anim["rightwalk"].IsPlaying then
				anim["rightwalk"]:Play()
			end
			anim["rightwalk"]:AdjustWeight(X*-1.2)
			anim["leftwalk"]:Stop()
			--print(X*-1.2)
		elseif X > 0 and not UIS:IsKeyDown(Enum.KeyCode.W) and not UIS:IsKeyDown(Enum.KeyCode.S) then
			anim["rightwalk"]:Stop()
			if not anim["leftwalk"].IsPlaying then
				anim["leftwalk"]:Play()
			end
			anim["leftwalk"]:AdjustWeight(X*1.2)
			--print(X*1.2)
		elseif X > 0 and Z > 0 then
			anim["rightwalk"]:Stop()
			if not anim["leftwalk"].IsPlaying then
				anim["leftwalk"]:Play()
			end
			anim["leftwalk"]:AdjustWeight(X*0.4)
		elseif X > 0 and Z < 0 then
			anim["rightwalk"]:Stop()
			if not anim["leftwalk"].IsPlaying then
				anim["leftwalk"]:Play()
			end
			anim["leftwalk"]:AdjustWeight(X*0.4)
		elseif X < 0 and Z > 0 then
			if not anim["rightwalk"].IsPlaying then
				anim["rightwalk"]:Play()
			end
			anim["rightwalk"]:AdjustWeight(X*-0.4)
			anim["leftwalk"]:Stop()
		elseif X < 0 and Z < 0 then
			if not anim["rightwalk"].IsPlaying then
				anim["rightwalk"]:Play()
			end
			anim["rightwalk"]:AdjustWeight(X*-0.4)
			anim["leftwalk"]:Stop()
		end
	end
end)
	

This script replicates 100% correctly and doesn’t suffer the animation weight problem. I highly recommend this method to the OP’s.

5 Likes

truly a step up from my version which just gets rid of a lot of unnecessary/weird code

game:GetService("RunService").Heartbeat:Connect(function()
	for i,v in pairs(anim) do
		v:AdjustSpeed(humanoid.WalkSpeed/16)
	end
	local movedir = character.HumanoidRootPart.CFrame:vectorToObjectSpace(humanoid.MoveDirection)
	local currentstate = humanoid:GetState()
	X = movedir.X
	Z = movedir.Z
	local distZ,distZMin = ((character.PrimaryPart.CFrame.LookVector * 5) - Vector3.new(0,0,Z)).Magnitude,((character.PrimaryPart.CFrame.LookVector * -5) - Vector3.new(0,0,Z)).Magnitude
	if Z == 0 then
		anim["backwalk"]:AdjustWeight(0.0001)
		anim["frontwalk"]:AdjustWeight(0.0001)
	elseif Z < 0 then
		anim["backwalk"]:AdjustWeight(0.0001)
		anim["frontwalk"]:AdjustWeight(-Z-0.0001)
	elseif Z > 0 then
		anim["backwalk"]:AdjustWeight(Z+0.0001)
		anim["frontwalk"]:AdjustWeight(0.0001)
	end
	if X == 0 then
		anim["leftwalk"]:AdjustWeight(0.0001)
		anim["rightwalk"]:AdjustWeight(0.0001)
	elseif X < 0 and Z == 0 then
		anim["leftwalk"]:AdjustWeight(-X-0.0001)
		anim["rightwalk"]:AdjustWeight(0.0001)
	elseif X > 0 and Z == 0 then
		anim["leftwalk"]:AdjustWeight(0.0001)
		anim["rightwalk"]:AdjustWeight(X+0.0001)
	elseif X > 0 and Z > 0 then
		anim["leftwalk"]:AdjustWeight(0.0001)
		anim["rightwalk"]:AdjustWeight(X+0.0001)
	elseif X > 0 and Z < 0 then
		anim["leftwalk"]:AdjustWeight(0.0001)
		anim["rightwalk"]:AdjustWeight(X+0.0001)
	elseif X < 0 and Z > 0 then
		anim["leftwalk"]:AdjustWeight(-X-0.0001)
		anim["rightwalk"]:AdjustWeight(0.0001)
	elseif X < 0 and Z < 0 then
		anim["leftwalk"]:AdjustWeight(-X-0.0001)
		anim["rightwalk"]:AdjustWeight(0.0001)
	end
		anim["idle"]:AdjustWeight(.2)
end)
2 Likes

So uh… Not trying to be dumb or anything but where would u place the script?
I’m still kinda new to scripting

Place this script in StarterPlayer > StarterCharacterScripts

2 Likes

i also made a version that dosent use key inputs or camera to detect in which direction the player is headed, u can find the post here: 8 Way Directional Walking System Open Sourced

3 Likes