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: