Hello fellow developers. I am currently making a soccer game and when the bezier of the ball finishes it sort of just stays floating for a bit and then goes down.
I am trying to make it go in the same trajectory it was going in even after the bezier is over.
The script
local function animateBall(Ball : Model, P0: Vector3, P1: Vector3, End: Vector3, Duration: number, Player : Player,HRP : Part)
local Start = os.clock()
local tD = task.wait()
local Connection
Connection = RunService.Heartbeat:Connect(function()
local t = math.clamp((os.clock() - Start) / Duration, 0, 1)
local newPos = quad(P0, P1, End, t)
HRP.BallWeld.Enabled = false
Ball.Ball.CFrame = CFrame.new(newPos) * CFrame.Angles(math.rad(.01) + Ball.Ball.Rotation.X, math.rad(.01) + Ball.Ball.Rotation.Y, math.rad(.01) + Ball.Ball.Rotation.Z)
if os.clock() - Start >= Duration then
Connection:Disconnect()
if End ~= Goal.Goal.Position then
Ball.Ball.Anchored = false
end
task.delay(1.5,function()
Ball.Ball.Anchored = false
Events.RemoteEvent:FireClient(Player,"StopSpectate")
Ball:PivotTo(HRP.CFrame)
HRP.BallWeld.Enabled = true
end)
return
end
end)
end