Custom movement animation issue

I am currently making a custom animation system for my game (using only C0s)

Everything is working fine; except for when I turn my character / change Y direction.
How it works is that it uses VectorToObjectSpace(humanoid.movedirection) to move the legs in the direction the player is moving. I thought that i could round the movedirection; but that did not work.

Any help would be great

Code:

local Plrs = game:GetService("Players");
local Plr = Plrs.LocalPlayer;
local Char = Plr.Character or Plr.CharacterAdded:Wait();
local Mouse = Plr:GetMouse();
local Cam = workspace.CurrentCamera

local RS = game:GetService("RunService");
local TS = game:GetService("TweenService");
local UIS = game:GetService("UserInputService");


Plr.Character:WaitForChild("Torso")
for i, track in pairs (Plr.Character.Humanoid:GetPlayingAnimationTracks()) do
	track:Stop()
end

local LLeg = Char.Torso["Left Hip"]
local RLeg = Char.Torso["Right Hip"]

local LArm = Char.Torso["Left Shoulder"]
local RArm = Char.Torso["Right Shoulder"]

local TTorso = Char.HumanoidRootPart["RootJoint"]

local OldLC0 = LLeg.C0;
local OldRC0 = RLeg.C0;
local OldTC0 = TTorso.C0;
local OldRAC0 = RArm.C0;
local OldLAC0 = LArm.C0;
local tilt = CFrame.new();
local yOFF = 0;

local leg1atch = Instance.new("Attachment", Char["Torso"])
leg1atch.Position = Vector3.new(-.5,-1,0)
leg1atch.Name = "atch1"
local leg2atch = Instance.new("Attachment", Char["Torso"])
leg2atch.Position = Vector3.new(.5,-1,0)
leg2atch.Name = "atch2"


local mmod = require(script.Math)
local smoothmove = script.Values.Moveal;


while true do
	RS.Stepped:Wait();
	
	local movemntFLOOR = mmod.roundVector(Char.Humanoid.MoveDirection,.5)
	print(movemntFLOOR)
	TS:Create(smoothmove,TweenInfo.new(.1),{Value = movemntFLOOR.Magnitude/2}):Play()
	--//Torso
	local movedir = Char.HumanoidRootPart.CFrame:VectorToObjectSpace(Vector3.new(Char.Humanoid.MoveDirection.X,0,Char.Humanoid.MoveDirection.Z))
	local vel = Char.HumanoidRootPart.Velocity.magnitude
	local movdd = 35 + (vel)
	local tilt = tilt:Lerp(CFrame.Angles(math.rad(-movedir.Z) * movdd, math.rad(-movedir.X) * movdd, 0), .2)
	
	local i2 = tick()*1.25
	if Char.Humanoid.FloorMaterial ~= Enum.Material.Air then
		yOFF = smoothmove.Value/15
		TTorso.C0 = TTorso.C0:lerp(OldTC0 * CFrame.new(0,-(yOFF*5), -yOFF*2 + math.abs(math.sin(i2*(Char.Humanoid.WalkSpeed/2))*smoothmove.Value)) * tilt * CFrame.Angles(math.rad(math.sin(i2*4)*2),math.rad(math.sin(i2*10)*vel/4),math.rad(math.cos(i2*10)*vel/4)) * CFrame.Angles(0,0,math.rad(movedir.X*-15)),.1)

		local i = tick()*1.25 + vel*4
		--//Left Leg

		local v1 = math.sin(i*(vel/15)*6.75)*33 * (vel/13)
		LLeg.C0 = LLeg.C0:lerp(CFrame.Angles(math.rad(movedir.Z*-v1 +3),math.rad(movedir.Y*v1 -8),math.rad(movedir.X*v1/1.4 ))*CFrame.Angles(0,math.rad(-90),0)*CFrame.new(((-1)*(vel/128)), -1+(math.sin(i*5)/(45/vel)/35),1.03),.07)
		local v2 = math.sin((i*(vel/15)*6.75)+3)*33 * (vel/13)
		RLeg.C0 = RLeg.C0:lerp(CFrame.Angles(math.rad(movedir.Z*-v2 +3),math.rad(movedir.Y*v2 +8),math.rad(movedir.X*v2/1.4 ))*CFrame.Angles(0,math.rad(90),0)*CFrame.new(((1)*(vel/128)),  -1+(math.sin(i*5)/(45/vel)/35),1.03),.07)
		
		
		RArm.C0 = RArm.C0:lerp(OldRAC0 * CFrame.Angles(math.rad(v1/15),0,math.rad(v1*1.5)),.05)
		LArm.C0 = LArm.C0:lerp(OldLAC0 * CFrame.Angles(math.rad(v1/15),0,math.rad(v1*1.5)),.05)
		
		
	else
		TTorso.C0 = TTorso.C0:lerp(OldTC0 * CFrame.new(0,-(yOFF*5), -yOFF*2 + math.abs(math.sin(i2*(Char.Humanoid.WalkSpeed/2))*smoothmove.Value)) * tilt * CFrame.Angles(math.rad(Char.HumanoidRootPart.Velocity.Y + math.sin(i2*4)*2),math.rad(math.sin(i2*10)*vel/4),math.rad(math.cos(i2*10)*vel/4)) * CFrame.Angles(0,0,math.rad(movedir.X*-15)),.1)
		RLeg.C0 = RLeg.C0:lerp(OldRC0 * CFrame.new(.3,1,.06),.1)
		LLeg.C0 = LLeg.C0:lerp(OldLC0 * CFrame.new(.3,.1,.06),.1)
	end
	--LLeg.C0 = LLeg.C0:lerp(CFrame.new(movedir+Char.HumanoidRootPart.Position,leg1atch.WorldPosition):toObjectSpace(Plr.Character.Torso.CFrame):inverse() * CFrame.Angles(0, -math.pi / 2, 0) * CFrame.new(0,-1,-.5), .35)
end

(please excuse my bad code)

1 Like

(Instead of using tick, use time)

Try inverting the CFrame you are using this with.