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)
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
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.
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)
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)
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