[Updated] Open-Source R15/R6 Character Momentum/Leaning

I made an open-source R15/R6 character momentum thing (I’m not sure if that’s the correct way to call this).

GIF of it in action:
https://i.gyazo.com/a592b404a45e9ff860dd5affaf03e3cd.mp4
The amount/speed the character is leaning at can be adjusted. I purposefully made the amount high in the GIF for demonstration purposes.

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)
92 Likes

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!

6 Likes

Seen you on the game Criminality before. This does seem handy for my upcoming project I am making.

3 Likes

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…

21 Likes

May I have this version if you don’t mind? :slight_smile:

2 Likes

Of course! Here’s a pastebin link with the code. Just paste it in where you’d put the original script. Enjoy! :smiley:

16 Likes

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…)
2 Likes

Had fun messing with it, def gunna use it in future games, Great job!

2 Likes

hey, is there a way to make your version R6?

this script already have r6 support so you don’t have to worry

this script doesn’t seem to work with streamingenabled ticked on, is that supposed to happen?

1 Like

hello this sometimes bug like this nowdays
image
hands are being very weird any fixes?

Workspace > Behavior > Retargeting turn it off

1 Like

so is this serversided or not, i have made similar scripts replicating this but all of them have been on the client and never replicated on the server

why is it copylocked?
Captura de tela 2023-09-29 062444