Orbit change won't work

Hello, I am making
orbs rotating around eachother. a rotates around orb b, but when I activate the event the orbiting changes and b rotates a round a. But the problem is that b doesn’t stay in position and continuous to orbit but it just tps

local RS = game:GetService("RunService")

local rp = game:GetService("ReplicatedStorage")

local space = rp:WaitForChild("space")
local b = script.Parent.B1
local a = script.Parent.B2

local speed = .5

local mag = 0
local angle = 0

space.OnServerEvent:Connect(function(plr)
			print("Player pressed space!")
			if a == script.Parent.B2 then
				b  = script.Parent.B2
				a = script.Parent.B1
			elseif a == script.Parent.B1 then
				b  = script.Parent.B1
				a = script.Parent.B2
			end

end)

RS.Heartbeat:Connect(function(dt)
	mag = (a.Position-b.Position).Magnitude
	angle = (angle + dt * (math.pi * speed)) % (2 * math.pi)
	b.CFrame = a.CFrame * CFrame.new(math.cos(angle) * mag, 0, math.sin(angle) * mag)
end)


This is what I am heading for:
straightline

Can you send a video of what happens instead of what you want? (Also nice ADOFAI, nice pick for a roblox game.)

1 Like

Here is the game so you can test it yourself. You need to press e to activate it. Ty! roblox.com/games/9921109293/Project-1

I couldn’t record a video since my pc has a glitch with not recording my screen

So from what i see, your issue comes from the fact that the other part keeps the orientation of the first part and it happens because the angle stays the same.

To fix that I suggest changing the angle whenever the player presses the spacebar, divide it maybe?

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