Source code can be found in StarterCharacterScripts > LocalScript in this uncopylocked place
or you can just copy and paste it from here
local runService = game:GetService("RunService")
local MOMENTUM_FACTOR = 0.008
local MIN_MOMENTUM = 0
local MAX_MOMENTUM = math.huge
local SPEED = 15
local character = script.Parent
local humanoid = character.Humanoid
local humanoidRootPart = character.HumanoidRootPart
local m6d = nil
local originalM6dC0 = nil
if humanoid.RigType == Enum.HumanoidRigType.R15 then
local lowerTorso = character.LowerTorso
m6d = lowerTorso.Root
else
m6d = humanoidRootPart.RootJoint
end
originalM6dC0 = m6d.C0
runService.Heartbeat:Connect(function(dt)
local direction = humanoidRootPart.CFrame:VectorToObjectSpace(humanoid.MoveDirection)
local momentum = humanoidRootPart.CFrame:VectorToObjectSpace(humanoidRootPart.Velocity)*MOMENTUM_FACTOR
momentum = Vector3.new(
math.clamp(math.abs(momentum.X), MIN_MOMENTUM, MAX_MOMENTUM),
0,
math.clamp(math.abs(momentum.Z), MIN_MOMENTUM, MAX_MOMENTUM)
)
local x = direction.X*momentum.X
local z = direction.Z*momentum.Z
local angles = nil
if humanoid.RigType == Enum.HumanoidRigType.R15 then
angles = {z, 0, -x}
else
angles = {-z, -x, 0}
end
m6d.C0 = m6d.C0:Lerp(originalM6dC0*CFrame.Angles(unpack(angles)), dt*SPEED)
end)
Interesting creation - I can’t think of any immediate use cases for myself but with some serious modification it could be used to create a more realistic movement system for games using Rthro. Games like GTA use this when you change direction suddenly, so maybe some form of that could be implemented in roblox. Thanks for the contribution!
I used your script and modified it somewhat to manipulate a couple more joints and eliminate forwards/backwards tilting, and the results are perfect! Thank you for this script, this will make movement in my game feel much more fun and satisfying.
Running in circles has never been more entertaining…
Updated the script with optimizations and some new features.
Added option to make momentum based off HumanoidRootPart velocity (if you don’t want to do this, just set MIN_MOMENTUM and MAX_MOMENTUM to the same number)
Using Heartbeat instead of RenderStepped (RenderStepped was unnecessary, I don’t know why I chose to use it over Heartbeat…)