Hi,
I am trying to make a part bounce and spin and so far have the code below, the bounce is working fine but the rotate keeps glitching and not rotating smothly, do anyone know what I am getting wrong? the part is in the workspace which I am running to code on and has a mesh attached.
local TweenService = game:GetService("TweenService")
local part = script.Parent
-- Bounce variables
local bounceHeight = 2
local bounceDuration = 1
local originalY = part.Position.Y
local bounceUpInfo = TweenInfo.new(bounceDuration / 2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local bounceDownInfo = TweenInfo.new(bounceDuration / 2, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
-- Spin variables
local spinSpeed = 5 -- Degrees per frame/small increment
local spinInfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out) -- Very short duration for smooth continuous spin
local function bounce()
while true do
local bounceUpGoal = {Position = Vector3.new(part.Position.X, originalY + bounceHeight, part.Position.Z)}
local bounceDownGoal = {Position = Vector3.new(part.Position.X, originalY, part.Position.Z)}
local tweenUp = TweenService:Create(part, bounceUpInfo, bounceUpGoal)
local tweenDown = TweenService:Create(part, bounceDownInfo, bounceDownGoal)
tweenUp:Play()
tweenUp.Completed:Wait()
tweenDown:Play()
tweenDown.Completed:Wait()
end
end
local function spin()
local currentRotation = part.Orientation.Y
while true do
currentRotation = (currentRotation + spinSpeed) % 360
local spinGoal = {Orientation = Vector3.new(part.Orientation.X, currentRotation, part.Orientation.Z)}
local tweenSpin = TweenService:Create(part, spinInfo, spinGoal)
tweenSpin:Play()
task.wait(0.01) -- Adjust this for desired spin smoothness/speed
end
end
-- Start both animations concurrently
task.spawn(bounce)
task.spawn(spin)