I am making a wall climbing system and I want the players head to face in the direction they are moving. I have that working but it only sets the C0, I want it to smoothly transition so I tried to use a lerp but I think I’m doing it wrong.
Here is a bit of the class I made to update the player head.
HeadMover.ConstraintAngles = Vector3.new(math.rad(30), math.rad(30), 0)
--relevant methods
function HeadMover:UpdateNeck(direction: Vector3, dt) --fired every runservice.Stepped
--the direction is the movement direction relative to the player primary part
self.head.CanCollide = false --not sure a better way to make the head not collide with the wall
if not direction or direction == Vector3.new() then
direction = self.hrp.CFrame.LookVector
end
direction = direction.Unit
local RotationOffset = (self.char.PrimaryPart.CFrame- self.char.PrimaryPart.CFrame.p):inverse()
local DesiredHeadCF = RotationOffset * CFrame.new(Vector3.new(0,0,0), direction)
local newNeckC0 = self:LerpNeck(DesiredHeadCF, dt)
self.neck.Transform = newNeckC0
end
function HeadMover:LerpNeck(CF, dt)
local X, Y = HeadMover.ConstraintAngles.X, HeadMover.ConstraintAngles.Y
-- goal
local x, y = CF:toEulerAnglesXYZ() -- goal angle
local goalCF = CFrame.new(CF.p) * CFrame.Angles(
math.clamp(x, -X, X),
math.clamp(y, -Y, Y),
0
) -- constrain angles and construct cframe
local interpolatedCF = self.neck.C0:Lerp(goalCF, dt) -- lerp
return interpolatedCF
end
I’m not sure how to get the lerp to move smoothly. Thank you for your time.