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 5 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 — 5y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
5 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 ;

01local reference = workspace.Part;   --Part to orbit
02local ps = 3;                       --Number of parts to orbit
03local offset = 1;                   --Offset from the reference
04 
05for i = 1,360,360/ps do             --Implement summand into step
06    local orig = reference.CFrame;
07    local rot = CFrame.Angles(0,math.rad(i),0); --Assuming this is your axis
08    local dist = CFrame.new(0,0,-offset);
09    local p = Instance.new("Part");
10    p.CFrame = orig*rot*dist;
11    p.Size = Vector3.new(1,1,1);
12    p.Anchored = true;
13    p.Parent = workspace;
14end
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 — 5y
Ad

Answer this question