I’m trying to make a character not just lean, but kind of rotate the body to face where the player is currently moving. My current code has an ongoing issue with having the limbs twist weirdly.
What I’m going for: Watch Example | Streamable (Pretty sure it’s different animations; I want it to be the same animation with manipulating a rig’s motors)
What my code does: Watch Example | Streamable (Limbs don’t twist in the right direction; I’ve tried rotating them in the complete opposite direction, but it wasn’t going in my favor)
My code:
local ActionData = {
SideVector = Character.PrimaryPart.CFrame.RightVector:Dot((Character.PrimaryPart.Velocity * Vector3.new(1, 0, 1)).Unit)
FrontVector = Character.PrimaryPart.CFrame.LookVector:Dot((Character.PrimaryPart.Velocity * Vector3.new(1, 0, 1)).Unit)
}
local rotation = 65 -- How much the rig will rotate
local sideVector = math.rad(ActionData.SideVector * rotation) -- Multiplying it by the direction the player is going
-- originalC0s are the unchanged C0s which it bases off of
neckJoint.C0 = neckJoint.C0:Lerp(originalC0s.Neck * CFrame.Angles(math.rad(ActionData.FrontVector * 10), sideVector - sideVector / 3, 0), 0.1)
waistJoint.C0 = waistJoint.C0:Lerp(originalC0s.Waist * CFrame.Angles(0, sideVector / 3, 0), 0.1)
rootJoint.C0 = rootJoint.C0:Lerp(originalC0s.Root * CFrame.Angles(math.rad(ActionData.FrontVector * -10), -sideVector, 0), 0.1)