Still have questions? Join our Discord server and get real time help.
Log in to vote

how do I detect how fast a player changes direction?

Asked by 4 days ago

I want to make the player model tilt towards the direction the player is moving (the quicker it changes direction, the more the player model tilts) and I don't really know how to do either (detect change in direction and tilt player model) could anyone help? Cheers!

1 answer

Log in to vote
Answered by
Elyzzia 1023 Moderation Voter
4 days ago
Edited 4 days ago

you can simply use the Y component of the HumanoidRootPart's RotVelocity to find the speed the player is rotating at, then base the amount of tilt on that number

to actually apply the tilt, you can change the Transform of the character's root joint

where that joint is located and what it's called depends on whether your game is r6 or r15

if you want it to appear smooth you can repeatedly lerp the Transform instead of just constantly setting it

-- LocalScript in StarterCharacterScripts
local RunService = game:GetService("RunService")

local char = script.Parent
local rootPart = char:WaitForChild("HumanoidRootPart")
local rootJoint = rootPart:WaitForChild("RootJoint") -- change this to char:WaitForChild("LowerTorso"):WaitForChild("Root") if your game uses R15
-- if your game supports both you'll have to check to see which the character uses with Humanoid.RigType

local transform =
local originalC0 = rootJoint.C0

rootJoint:GetPropertyChangedSignal("C0"):Connect(function() -- account for changes to the C0 made by actual roblox scripts
    if rootJoint.C0 ~= originalC0 * transform then
        originalC0 = rootJoint.C0

    local tilt = math.clamp(rootPart.RotVelocity.Y * 4, -45, 45)
    transform = transform:Lerp(CFrame.Angles(0, math.rad(tilt), 0), 0.25 * delta * 60) -- you can change 0.25 here to whatever you want
    rootJoint.C0 = originalC0 * transform

if you want other people to be able to see tilt as well, you can copy and paste the same code into a server script, but with RenderStepped replaced with Heartbeat

Cant get it to work. Am i doing anything wrong? Scrufflord 12 — 4d
is there an error Elyzzia 1023 — 4d
OK i figured out what was wrong, apparently the character doesn't like it when you change its Transform and just does. literally nothing Elyzzia 1023 — 4d
i updated the code to actually. you know, work Elyzzia 1023 — 4d

Answer this question