Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I make objects orbit evenly?

Asked by 4 years ago

How do I multiple objects orbit a brick evenly? So, if there are two satellites, they are on opposite sides. If three satellites, space between them is a third. All automatically.

0
this is not a request site Gameplayer365247v2 1055 — 4y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
4 years ago

Logic

You need to figure out how much to rotate each part in orbit, initially. Once they are placed you may continue to rotate each simultaneously.

A circle has 360ยบ. The quotient of 360 and the number of parts is going to be the summand that will rotate each part in even relation to one another..

360/2 = 60

360/3 = 120

You may use a for loop to easily implement this into the step syntax;

for [variable] = [start],[finish],[step] do

--code

end


Code

Here is an example ;

local reference = workspace.Part;   --Part to orbit
local ps = 3;                       --Number of parts to orbit
local offset = 1;                   --Offset from the reference

for i = 1,360,360/ps do             --Implement summand into step
    local orig = reference.CFrame;
    local rot = CFrame.Angles(0,math.rad(i),0); --Assuming this is your axis
    local dist = CFrame.new(0,0,-offset);
    local p = Instance.new("Part");
    p.CFrame = orig*rot*dist;
    p.Size = Vector3.new(1,1,1);
    p.Anchored = true;
    p.Parent = workspace;
end
0
So, I tried to combine your code with someone else's code to make it actually spin. But I am really bad at all this math and comprehension as you can tell, https://pastebin.com/raw/ruEvWHgF. They all end up orbiting at the same angle. Know why? devisings 58 — 4y
Ad

Answer this question