How do i make Realistic Walking/Running?

So, i’ve seen some games that has this realistic looking movement animation, i currently have no idea on how to achieve something like this :

Soul Shatters are one of the game that uses this realistic moving, the other one i seen that use this is A Bizzare Day and Joi Joi, but the best one is SoulShatters.

Edit : I’ve done it! at last! thanks for all the help guys!
this is my current results, i use Animations Weight and Humanoid.MoveDirection


Sorry for the laggy video i recorded it in studio.
The Code :

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local agility = character:WaitForChild("Agility")
local UIS = game:GetService("UserInputService")
script:WaitForChild("leftwalk"):WaitForChild("Animation")
local currently_playing_anim = {}
local anim = {
	["frontwalk"] = humanoid:LoadAnimation(script.forwardwalk.Animation);
	["backwalk"] = humanoid:LoadAnimation(script.backwalk.Animation);
	["rightwalk"] = humanoid:LoadAnimation(script.rightwalk.Animation);
	["leftwalk"] = humanoid:LoadAnimation(script.leftwalk.Animation);
	["frontrun"] = humanoid:LoadAnimation(script.forwardrun.Animation)
	}
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

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


game:GetService("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
		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)
			humanoid.WalkSpeed = agility.Value
		if humanoid.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)
		humanoid.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)
36 Likes

Google.

10 Likes

not that lol. don’t you see something different in the video? when you lock your camera and press A the character legs will move sideways.
that’s just a tutorial on how to make animations, i already know that.
and also the body rotates depends on what you press.

7 Likes

Ok i don’t know how to make it :joy:
But you can try this game Platformer movement - Roblox
And you want to make that Walking/Running animation right? So you can edit it.

6 Likes

yeah, that’s exactly what i meant! :smile:

4 Likes

Its called strafing you can find some resources on devforum

5 Likes

While making animations you can use the Joints toggle to turn on inverse kinematics and that allows you to create animations using it. You can then create 8 animations for each direction. 4 for the normal directions and 4 for the diagonal directions.

Alternatively you can animate the legs by code using inverse kinematics again. This would make your game look a bit better on mobile devices since they aren’t constrained to 8 movement directions.

22 Likes

Well you should have been more specific, your lack of details makes it seems like you just want to know how to make a walking animation.

3 Likes

Also what you could do is add a CameraBobble effect, I fabricated this simple script for a game and it works. Make sure to put it into a LocalScript:

local runService = game:GetService("RunService")

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

function updatedBobbleEffct()
	local currentTime = tick()
	if humanoid.MoveDirection.Magnitude > 0 then
		local bobbleX = math.cos(currentTime * 0) * 1
		local bobbleY = math.abs(math.sin(currentTime * 10)) * 1
		
		local bobble = Vector3.new(bobbleX, bobbleY, 0)
		
		humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, .25) --25
	else
		humanoid.CameraOffset = humanoid.CameraOffset * .100 --75
	end
end

runService.RenderStepped:Connect(updatedBobbleEffct)
4 Likes

You could use inverse kinematics. If you don’t know how to do that, then I suggest you watch this youtube video that I found yesterday.

EDIT: Please check the description of the video as well!

8 Likes

Does it replicate to the server? I tried this method but it doesn’t replicated for other players.

1 Like

it does replicate for me (30 charssssssss)

Where did you place the local script at? I placed it in StarterCharacterScripts, and created the Agility value through a server script that’s placed in ServerScriptService.

i hope this isn’t necroposting or anything, but i’m trying to achieve the same effect for a project i’m working on.

i looked at the script that you gave showing how you coded it and immediately noticed you referenced an ‘agility’ instance in the character. what is that??

also, did you follow a tutorial when writing the code or did you just know how to do it from looking at examples of it? i tried searching on yt for tutorials of it, but all i could find was a video explaining how simple it is to make the base animations; nothing about the actual coding of it. i’m really interested in learning how to do this; any advice would be helpful.

yes, so, agility is an IntValue i made to control humanoid walkspeed, as you can see humanoid WalkSpeed cant go below 0 so i made an IntValue named agility that controls the humanoid WalkSpeed.
you can change the agility to humanoid.WalkSpeed

and no, i didnt follow a tutorial, i just came up with an idea to achieve the effect by using humanoid.MoveDirection and AnimationWeight.

So basically how the script works is by getting the MoveDirection of the humanoid, after we get the movedirection we can play the animation we just made based on the MoveDirection of the humanoid and add some weights to it making it looks like the video above.

2 Likes

thank you so much! you’re a life saver.

Hey just wondering if the code in the topic at the top is the working code or the code from the beginning?

Because if you wouldn’t mind I could use it for my fighting game your choice tho

The code in the topic is working but you need to set it up based on the variables.

Yep understand that such as changing the animation ids and such

1 Like

is there a way I could change the 4 way movement to an 8 way movement system, like back left, back, back right, right, forward right, forward, ect.

–i figured it out

1 Like