How i can do Realistic Walkig

How i can do relistic walking like in Soul Shatters?
My try:

local plr = game.Players.LocalPlayer
local char = plr.Character
local root = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local agility = char:WaitForChild("Agility")
script:WaitForChild("Anims")
local currently_playing_anim = {}
local anim = {
	["frontwalk"] = hum:LoadAnimation(script.Anims.foward);
	["backwalk"] = hum:LoadAnimation(script.Anims.back);
	["rightwalk"] = hum:LoadAnimation(script.Anims.left);
	["leftwalk"] = hum:LoadAnimation(script.Anims.right);
	["frontrun"] = hum:LoadAnimation(script.Anims.run)
	}
local X,Z = 0,0
for i,v in pairs(anim) do
	v:Play()
	v.Looped = true
end
local function setallweight(num)
	for i,v in pairs(anim) do
		v:AdjustWeight(num)
	end
end

hum:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
	anim["backwalk"]:AdjustSpeed(hum.WalkSpeed/10)
	anim["frontwalk"]:AdjustSpeed(hum.WalkSpeed/10)
	anim["frontrun"]:AdjustSpeed(hum.WalkSpeed/25)
end)


game:GetService("RunService").RenderStepped:Connect(function()
	local movedir = char.HumanoidRootPart.CFrame:vectorToObjectSpace(hum.MoveDirection)
	local currentstate = hum:GetState()
	X = movedir.X
	Z = movedir.Z
	local distZ,distZMin = ((char.PrimaryPart.CFrame.LookVector * 5) - Vector3.new(0,0,Z)).Magnitude,((char.PrimaryPart.CFrame.LookVector * -5) - Vector3.new(0,0,Z)).Magnitude
	print("X = "..movedir.X.." Z = "..movedir.Z)
	if currentstate == Enum.HumanoidStateType.Jumping then
		setallweight(0)
	elseif currentstate == Enum.HumanoidStateType.Freefall then
		setallweight(0)
	else
		if Z == 0 then
			anim["backwalk"]:AdjustWeight(0)
			anim["frontwalk"]:AdjustWeight(0)
			anim["frontrun"]:AdjustWeight(0)
	elseif Z < 0 then
			anim["backwalk"]:AdjustWeight(0)
			hum.WalkSpeed = agility.Value
		if hum.WalkSpeed < 20 then
			anim["frontwalk"]:AdjustWeight((Z*-1.1)-((agility.Value/10)-1))
			anim["frontrun"]:AdjustWeight((agility.Value/10)-1)
		else
			anim["frontrun"]:AdjustWeight(Z*-1.1)
			anim["frontwalk"]:AdjustWeight(1-((agility.Value/10)-1))
		end
	elseif Z > 0 then
		anim["backwalk"]:AdjustWeight(Z*1.1)
		anim["frontrun"]:AdjustWeight(0)
		anim["frontwalk"]:AdjustWeight(0)
		hum.WalkSpeed = agility.Value/2
	end
	if X == 0 then
		anim["rightwalk"]:AdjustWeight(0)
		anim["leftwalk"]:AdjustWeight(0)
	elseif X < 0 and not UIS:IsKeyDown(Enum.KeyCode.W) and not UIS:IsKeyDown(Enum.KeyCode.S) then
		anim["rightwalk"]:AdjustWeight(X*-1.2)
		anim["leftwalk"]:AdjustWeight(0)
			--print(X*-1.2)
	elseif X > 0 and not UIS:IsKeyDown(Enum.KeyCode.W) and not UIS:IsKeyDown(Enum.KeyCode.S) then
		anim["rightwalk"]:AdjustWeight(0)
		anim["leftwalk"]:AdjustWeight(X*1.2)
			--print(X*1.2)
	elseif X > 0 and Z > 0 then
		anim["rightwalk"]:AdjustWeight(0)
		anim["leftwalk"]:AdjustWeight(X*0.4)
	elseif X > 0 and Z < 0 then
		anim["rightwalk"]:AdjustWeight(0)
		anim["leftwalk"]:AdjustWeight(X*0.4)
	elseif X < 0 and Z > 0 then
		anim["rightwalk"]:AdjustWeight(X*-0.4)
		anim["leftwalk"]:AdjustWeight(0)
	elseif X < 0 and Z < 0 then
		anim["rightwalk"]:AdjustWeight(X*-0.4)
		anim["leftwalk"]:AdjustWeight(0)
	end
		
	end
	
end)

4 Likes

Just make some nice looking animations. I recommend using moon animator.

Dude my script its buggy, i need somehow fix it. About animations i already did

It looks okay when you are just walking in one direction, but it seems that your animations start bugging out when walking in a diagonal way. My best assumption for how to fix this is to create separate animations for when a combination of keys are pressed. For example, in some games there is typically a jump animation and a walk animation, however, when the character jumps while walking, the jump will seem unrealistic. The best way developers have combated this is to create a third animation, a walk-jump.

tl;dr: transitional animations.