Running Animation Tilting/Lean

Hey! Apologies if this is the wrong area for this, but recently I have been trying to make my own combat system, and along with that comes running/walking animations. Specifically, I was wondering how I could replicate this tilt/lean that the torso or whatever is doing when going in specific directions.

[Not looking for code, just a nudge in the right direction]
Is this done with multiple animations for each direction? or is this done with math via code.

https://streamable.com/6s3wv2

1 Like

Solution found!

For anyone who may find this post in the future and is looking for a solution, here is the one I ended up by using [R15 Only currently]

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local Player = Players.LocalPlayer
local Character = script.Parent
local Humanoid = Character:WaitForChild"Humanoid"

local HumanoidRootPart = Character.HumanoidRootPart
local LUL = Character.LeftUpperLeg
local RUL = Character.RightUpperLeg
local LowerTorso = Character.LowerTorso
local UpperTorso = Character.UpperTorso

local RootJoint = LowerTorso.Root
local LeftHipJoint = LUL["LeftHip"]
local RightHipJoint = RUL["RightHip"]

local function Lerp(a, b, c)
	return a + (b - a) * c
end

local Force = nil
local Direction = nil
local Value1 = 0
local Value2 = 0

local RootJointC0 = RootJoint.C0
local LeftHipJointC0 = LeftHipJoint.C0
local RightHipJointC0 = RightHipJoint.C0

RunService.RenderStepped:Connect(function()
	Force = HumanoidRootPart.Velocity * Vector3.new(1,0,1)
	if Force.Magnitude > 2 then
		Direction = Force.Unit	
		Value1 = HumanoidRootPart.CFrame.RightVector:Dot(Direction)
		Value2 = HumanoidRootPart.CFrame.LookVector:Dot(Direction)
	else
		Value1 = 0
		Value2 = 0
	end

	RootJoint.C0 = RootJoint.C0:Lerp(RootJointC0 * CFrame.Angles(math.rad(Value2 * 10), math.rad(-Value1 * 10), 0), 0.2)
	LeftHipJoint.C0 = LeftHipJoint.C0:Lerp(LeftHipJointC0 * CFrame.Angles(math.rad(-Value1 * 10), 0, 0), 0.2)
	RightHipJoint.C0 = RightHipJoint.C0:Lerp(RightHipJointC0 * CFrame.Angles(math.rad(Value1 * 10), 0, 0), 0.2)
end)
2 Likes