Movement and orbiting help

I have been trying to figure out how to make stuff moveable and orbit other blocks. The reason for that is because I am making a showcase


the point is that basically I want all the fire blocks to rotate around the non fire blocks and the ability to speed it up as it spins more and more, eventually creating a full flame of something like this ezgif.com-gif-maker

You could use constraints to do this

Hello,
use math.sin idk how because I’ve never studied trigonometry and I don’t know how to do it but I think it’s related to sine waves

Hello there,

This seems to be what you want. I’ve added the ability to customize the speed of the orbits as well as a commented out section (the “break” part) to stop it if it completes one orbit. The place file is attached for your to play around with but the code is also posted along with my Explorer setup.

Place file: orbit.rbxl (22.9 KB)

– Code in case you don’t want to open the place file (plus explorer setup)

image

local rs = game:GetService("RunService")
local objects = workspace:WaitForChild("singlePlane"):GetChildren()
local center = workspace.sun
local distanceFromCenter = 10
local timeToOrbit = 3

-- Ignore these, they are for internal working
local radiansPerSecond = (math.pi * 2)/timeToOrbit
local currentRotation = 0
local startTime = nil;
local partAngles = {} -- Start angles for parts, found during the loop

while true do
	
	-- Get how long the Lua frame took
	local step = rs.Heartbeat:Wait()
	
	-- Ignore lag (for now, uncomment in production games to account for lag)
	if (step > 1) then
		continue
	end
	
	currentRotation += radiansPerSecond * step
	
	for _, part in pairs(objects) do
		local startAngle = partAngles[part]
		
		-- If there is no start angle, the orbit just started and we need to get one
		if (not startAngle) then
			startAngle = -math.atan2(part.Position.Z - center.Position.Z, part.Position.X - center.Position.X)
			partAngles[part] = startAngle
		end
		
		-- Set the CFrame to the center, then rotate the part on the Y axis angle, then push it outwards the orbit radius
		part.CFrame = CFrame.new(center.Position) * CFrame.fromAxisAngle(Vector3.new(0,1,0), startAngle + currentRotation) * CFrame.new(0,0,distanceFromCenter)
	end
	
	-- This is just for measuring the time it took is proper
	if (not startTime) then
		startTime = tick()
	end
	
	-- Comment this out to continue orbiting
	if (currentRotation >= (math.pi * 2)) then
		print(("Orbit finished in %f"):format(tick() - startTime))
		currentRotation = 0
		--break
	end
end
3 Likes