I have a ball that I have placed on the ground in Roblox Studio, and I wish to make it oscillate back and forth (jump up and down) forever. Here I used TweenService to animate its position relative to itself; first it goes up, then it goes down.
local BouncingBall = script.Parent
local tweenService = game:GetService("TweenService")
while true do
local goalUp = {}
goalUp.CFrame = BouncingBall.CFrame:ToWorldSpace(CFrame.new(0, 20 , 0))
local tweenInfoUp = TweenInfo.new(2, Enum.EasingStyle.Bounce)
local tweenUp = tweenService:Create(BouncingBall, tweenInfoUp, goalUp)
tweenUp:Play()
--print("Up")
wait(0.5)
local goalDown = {}
goalDown.CFrame = BouncingBall.CFrame:ToWorldSpace(CFrame.new(0, -20, 0))
local tweenInfoDown = TweenInfo.new(2, Enum.EasingStyle.Bounce)
local tweenDown = tweenService:Create(BouncingBall, tweenInfoDown, goalDown)
tweenDown:Play()
--print("Down")
wait(0.5)
end
However, when I start the game, for some reason the ball is doing the oscillation motion above the ground:
What is the mistake here? Why is the ball going up in the air first before doing the bounce motion?