Have this ‘cross dribble’ script which lerps the ball to middle position, then to the other hand back in the exact same way inside heartbeat. It works fine if the player stays still but if the player starts moving then it follows the player around and goes behind. I do know it’s because of the lerping but don’t know what would be the fix for it.
Here is my code
local currentOffset = character.HumanoidRootPart.CFrame:ToObjectSpace(ball.CFrame)
crossDribbleConnection = RunService.Heartbeat:Connect(function(t)
local groundObj = workspace:Raycast(character.HumanoidRootPart.Position, character.HumanoidRootPart.CFrame.UpVector * -100, raycastFilter)
if groundObj then
local groundHeight = groundObj.Position.Y
if on then
alpha = alpha + 0.015
if alpha <= 0.2 then
local rightHandPos = character.RightHand.Position
local midPos = (character.RightHand.Position + character.LeftHand.Position)/2
local currentPosition = character.HumanoidRootPart.CFrame * currentOffset
ball.CFrame = currentPosition
local targetPosition = Vector3.new(midPos.X , groundHeight, midPos.Z)
ball.Position = currentPosition.Position:Lerp(targetPosition, alpha)
currentOffset = character.HumanoidRootPart.CFrame:ToObjectSpace(ball.CFrame)
else
local currentPosition = character.HumanoidRootPart.CFrame * currentOffset
ball.CFrame = currentPosition
local targetPosition = character.RightHand.Position
ball.Position = currentPosition.Position:Lerp(targetPosition, alpha)---0.2)
currentOffset = character.HumanoidRootPart.CFrame:ToObjectSpace(ball.CFrame)
if alpha >= 0.4 then
on = false
alpha = 0
end
end
else
alpha = alpha + 0.015
if alpha <= 0.2 then
local rightHandPos = character.RightHand.Position
local midPos = (character.RightHand.Position + character.LeftHand.Position)/2
local currentPosition = character.HumanoidRootPart.CFrame * currentOffset
ball.CFrame = currentPosition
local targetPosition = Vector3.new(midPos.X , groundHeight, midPos.Z)
ball.Position = currentPosition.Position:Lerp(targetPosition, alpha)
currentOffset = character.HumanoidRootPart.CFrame:ToObjectSpace(ball.CFrame)
else
local currentPosition = character.HumanoidRootPart.CFrame * currentOffset
ball.CFrame = currentPosition
local targetPosition = character.LeftHand.Position
ball.Position = currentPosition.Position:Lerp(targetPosition, alpha-0.2)
currentOffset = ball.CFrame:ToObjectSpace(character.HumanoidRootPart.CFrame)
if alpha >= 0.4 then
on = true
alpha = 0
end
end
end
end
end)