Help with CFrame

I have a script that makes a part revolve around the player. But, at the same time, I want the part to bounce up and down. I have tried to tween the part individually and have tried to use a variable that represents the Y axis.

LocalScript:

local event = game.ReplicatedStorage.Client.SSAGenerated
local char = game.Players.LocalPlayer.Character
local head = char:FindFirstChild("Head")

event.OnClientEvent:Connect(function()
	local SeverStorage = game:GetService("ServerStorage")
	local StarUncloned = workspace.PassiveStar
	
	local Star = StarUncloned:Clone()
	Star.Parent = game.Players.LocalPlayer.Character
	Star.Position = game.Players.LocalPlayer.Character:FindFirstChild("Head").Position
	Star.Orientation = Vector3.new(0,0,0)
	
	local FullCircle = 2 * math.pi
	local radius = 3
	
	local function getXAndZPositions(angle)
		local x = math.cos(angle) * radius
		local z = math.sin(angle) * radius
		return x, z
	end
	for Time = 0,100,0.01 do
		local angle = Time * (FullCircle / 1.2)
		
		local x, z = getXAndZPositions(angle)
		
		
		local position1 = (head.CFrame * CFrame.new(x,0,z)).p
		
		Star.CFrame = CFrame.new(position1)
		task.wait()
	end
end)

What happens if you just add a y value to that CFrame.new in place of the zero, which is a sinusoidal function of time at a faster rate than rotation, like

y = math.sin(N*angle) * halfBounceHeight

Where in this case N is how many times you want it to bounce up and down during one revolution around the head, say N=20 for starters.

for Time = 0, 100, 0.01 do
	local angle = time * (fullCircle / 1.2)
	local x, z = getXAndZPositions(angle)
	local position1 = (head.CFrame * CFrame.new(x, 0, z)).p
	
	-- Bounce Effect
    local bounceHeight = 1  -- Adjust this value for desired bounce height

	local bounceOffset = math.abs(math.sin(Time * 2)) * bounceHeight
	star.CFrame = CFrame.new(position1 + Vector3.new(0, bounceOffset, 0))
	
	task.wait()
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.