I am trying to make a custom humanoid system, and currently I am rotating only the Y rotation of the humanoid to face the movement point. It works fine, but I encountered an issue where since the angles are between -180 to 180, if I’m facing slightly left backwards (-170) then turn slightly right (190) the lerp function wraps all the way around and the bot does a 360.
I’m making a game that plans to have thousands of humanoidless bots using this system, lerping a CFrame is far more expensive than lerping a single number.
Like I said in the earlier reply, I am planning to have a lot of this script running at once and lerping all the components of a CFrame is far more expensive than just one number.
Ok, so I decided to just use the CFrame:Lerp method even though I wanted to avoid it. Upon seeing all the steps that the code @BeatlessOghuz posted, I think CFrame:Lerp will be around the same or better. However, if you are looking for a solution to the original problem that’s not CFrame:Lerp(),the code beatless posted in the github link looks right and probably works if you translate it. If anyone is curious or wants to use my solution, here is the code:
local function lerpYOrientation(targetCFrame, currentCFrame)
local currentAngle = CFrame.Angles(0, select(2, currentCFrame:ToOrientation()), 0)
local targetAngle = CFrame.Angles(0, select(2, targetCFrame:ToOrientation()), 0)
return CFrame.new(targetCFrame.Position) * currentAngle:Lerp(targetAngle, 0.1)
end