Make Part lean forward depending on Character direction

I’m trying to make a part lean forward or backwards whenever character is on that axis, it works on sideways but not forwards/backwards.

local movementVector = _starterModel.HumanoidRootPart.CFrame:VectorToObjectSpace(_starterModel.Humanoid.MoveDirection)
tiltZ = math.clamp(Lerp(tiltZ, movementVector.X,0.2),-0.5,0.5)
tiltX = math.clamp(Lerp(tiltX, math.abs(math.clamp(movementVector.Z,-1,0)),0.2),0,0.25)

local x1,y1,z1 = _starterModel.HumanoidRootPart.CFrame:ToEulerAnglesXYZ()
local cf = CFrame.new(_starterModel.HumanoidRootPart.Position + partRoot.CFrame.LookVector) * CFrame.Angles(tiltX,0,tiltZ)

gyro.CFrame = v:GetAttribute("_gyroCF")*CFrame.Angles(tiltX,0,tiltZ)

bump, still looking for help on this one

genuinely dont know if im shadowbanned or not but still looking for any help on this one.
making just getting a part direction where its moving and leaning it.

what do you exactly mean by making it lean based on direction? as in when the player walks or just in general?

basically im trying to make a “pet follow” system where it follows the player’s back and leans towards the direction its on with a slight delay before it actually starts following the player.
I’m using BodyPosition and BodyGyro

I updated the movement system a bit however it’s still not leaning towards the direction the part is heading too. (nextPos)

--_ctrl:SetAttribute("_gyroCF", _ctrl.HumanoidRootPart.BodyGyro.CFrame) -- Strict axis on Z.
local prevPos = droot.Position

local rotVel = Vector3.new(0,0,0)

local nextPos = _starterModel.HumanoidRootPart.CFrame * CFrame.new(-2,2,3)
local distV = nextPos.Position - prevPos

local angleMod = CFrame.Angles(math.rad(rotVel.X)*30,0,math.rad(rotVel.Z)*30)

local CF = CFrame.new(nextPos.Position)*angleMod*CFrame.Angles(0,0,math.rad(90))

local gyro = droot.BodyGyro
local bpos:BodyPosition = droot.BodyPosition

gyro.CFrame = v:GetAttribute("_gyroCF")*angleMod
bpos.Position = CF.Position

Found out a way to detect if its moving backwards or forwards but is there a way to fully incorporate it with the leaning?

local tiltZ = 0
local tiltX = 0

local movementVector = droot.CFrame:VectorToObjectSpace((CF.Position - droot.Position).Unit)
tiltZ = math.clamp(Lerp(tiltZ, movementVector.X,0.5),-0.5,0.5)
tiltX = math.clamp(Lerp(tiltX, math.abs(math.clamp(movementVector.Z,-1,0)),0.5),0,0.55)
		
local dirCF = CFrame.Angles(tiltX, 0, tiltZ)
if math.clamp((CF.Position - droot.Position).Unit:Dot(droot.CFrame.LookVector) + 0.1, -1, 1) == 1 then
	print("moving forward")
elseif math.clamp((CF.Position - droot.Position).Unit:Dot(droot.CFrame.LookVector) + -0.1, -1, 1) <= -1 then
	print("moving backward")
end
		

bump, still looking for this.
this is the result im trying to achieve.
when moving forward the part would tilt like this on its BodyGyro.
image