How to tilt the character when you walk?

How would you achieve an effect like this?
When you walk and it tilts the way you walk.
(I saw another post about this, but it didn’t get any answers)

For the people that are also trying to figure this out:

wait(4)
local TweenService = game:GetService("TweenService")
root = workspace.Vyrrion.HumanoidRootPart
local dir, vel
local angle = 0
local original = root.RootJoint.C0
--looping code
hb = game:GetService("RunService")

hb.Heartbeat:Connect(function()
vel = root.Velocity * Vector3.new(1,0,1)
if vel.Magnitude > 2  then
    dir = vel.Unit
    angle = root.CFrame.RightVector:Dot(dir)/4.5 --will be between -1 and 1 based on how far off it is

	else
	
  angle = 0


end

local tweenInfo = TweenInfo.new(
	.2, -- Time
	Enum.EasingStyle.Quad, -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	0, -- RepeatCount (when less than zero the tween will loop indefinitely)
	false, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)
 
local tween = TweenService:Create(root.RootJoint, tweenInfo, {C0 = original*CFrame.Angles(0, -angle, 0)})
 
tween:Play()
--root.RootJoint.C0 = original*CFrame.Angles(0, -angle, 0)
end)
45 Likes

Rotate them based on the difference between their current angle/direction and the angle/direction of movement.
Example:

local dir, vel
local angle = 0
--looping code
vel = root.Velocity * Vector3.new(1,0,1)
if vel.Magnitude > 2 then
    dir = vel.Unit
    angle = root.CFrame.RightVector:Dot(dir) --will be between -1 and 1 based on how far off it is
else
    angle = 0
end
--some interpolation going on with the angle

Visual explanation:


The red line is the right vector, and the blue is the movement direction.

26 Likes

Could you help me on how I would put this into use, because I can’t figure it out.

This will compute a value judging how far away from the move direction the character is currently facing. You can use this to do something such as tilt the character by manipulating their Root joints by an angle that is based on this value.

This must be too complicated for me. I really can’t understand

It can be something as simple as rootJoint.C0 = CFrame.angles(0, 0, angle)

For some reason the angle is always nan(ind) and when I jump it becomes 0

Oh my bad, forgot to use <1,0,1> instead of <0,1,0>, try now

I think i’m getting closer but my character goes sideways as soon as the script starts
https://gyazo.com/d8cf38d0ca2aeeeca1758b956c26072d

4 Likes

Try manipulating the C1 or storing the original value before you modify it like this:

original = joint.C0
.......................
joint.C0 = original * myCF
1 Like

Thank you I got it to work!
(30 Character thing)

The script didn’t work for me :confused:

Well of course, the root joint has to be the root joint for the specific character, the loop comment literally means “find some way to execute this continuously”, and it should work assuming you eventually set or manipulate the joint data at all…

I can give you what i did, (it might be a bit cursed)

wait(4)

root = workspace.Vyrrion.HumanoidRootPart
local dir, vel
local angle = 0
local original = root.RootJoint.C0
--looping code
while wait() do
vel = root.Velocity * Vector3.new(1,0,1)
if vel.Magnitude > 2 and vel.Magnitude < 20 then
    dir = vel.Unit
    angle = root.CFrame.RightVector:Dot(dir)/2 --will be between -1 and 1 based on how far off it is

	else
	
  angle = root.CFrame.RightVector:Dot(dir)/2
end
print(angle)

root.RootJoint.C0 = original*CFrame.Angles(0, -angle, 0)
end

Why did you change what was in the else statement? It just resets the angle if they are moving way too slow (so they dont get stuck in a tilted angle while stationary)

2 Likes

I was trying stuff and i forgot about it

here i did it a bit better

wait(4)

root = workspace.Vyrrion.HumanoidRootPart
local dir, vel
local angle = 0
local original = root.RootJoint.C0
--looping code
hb = game:GetService("RunService")

hb.Heartbeat:Connect(function()
vel = root.Velocity * Vector3.new(1,0,1)
if vel.Magnitude > 2 and vel.Magnitude < 20 then
    dir = vel.Unit
    angle = root.CFrame.RightVector:Dot(dir)/2 --will be between -1 and 1 based on how far off it is

	else
	
  angle = 0
end
print(angle)

root.RootJoint.C0 = original*CFrame.Angles(0, -angle, 0)
end)
6 Likes

Thank you so much I’ve been struggling making a 3d
Platformer and trying to search for help

Same, we are lucky @Wunder_Wulfe was here to help out

How do you do it for multiple players instead of one?

1 Like

You are supposed to do it locally typically for just yourself. You can also do it for all other characters locally as if u do it on the server side, it will look a bit laggy