have a issue thats been bothering me past days and it is that the part movement gets stuttery/jittery as it goes in the else statement. I think its as im (the character) is moving and then because the animationPart speed is enough to keep reaching the goal target so it keeps switching between the 2 statements.
If the animationPart can’t keep up with the speed to reach its goal continuously then its very smooth and no issue at all
Problem is then the animationPart has speed to continuously reach its target while moving
Would appreciate any help on finding a solutions to this
1 Like
Have you tried to use Lerp ?
local SMOOTHING_FACTOR = 0.5 -- Adjust this value between 0-1 (lower = smoother but slower)
local MINIMUM_DISTANCE = 0.01 -- Threshold to prevent micro-adjustments
RunService.Heartbeat:Connect(function(deltaTime)
local targetCFrame = getTargetCFrame()
local currentFrame = getCurrentCFrame()
local distanceFromTargetCFrame = (targetCFrame.Position - currentFrame.Position).Magnitude
if distanceFromTargetCFrame > MINIMUM_DISTANCE then
local targetFrameDirection = (targetCFrame.Position - currentFrame.Position).Unit
local moveDistance = math.min(distanceFromTargetCFrame, deltaTime * 25)
local targetPosition = currentFrame.Position + (targetFrameDirection * moveDistance)
local smoothedPosition = currentFrame.Position:Lerp(targetPosition, SMOOTHING_FACTOR)
animationPart.CFrame = CFrame.new(smoothedPosition) * currentFrame.Rotation
end
end)