local SevenLights = game.Workspace.SevenLights
local Char
local EffectLight = {}
local function orbit(Character)
for _, light in pairs(SevenLights:GetChildren()) do
local ClonedLight = light:Clone()
local Weld = Instance.new("WeldConstraint")
Weld.Parent = ClonedLight
Weld.Part0 = Character.HumanoidRootPart
Weld.Part1 = ClonedLight
local RandomYLevel = math.random(8,25)
local RandomXLevel = math.random(-24,24)
local RandomZLevel = math.random(-15,15)
local TwoPowerFactor = math.random(1,2)
ClonedLight.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(RandomXLevel,RandomYLevel,RandomZLevel)
ClonedLight.Parent = Character
for Angle = 0, 360, 2 do
local Radian = math.rad(Angle)
local Sine = math.sin(Radian)*RandomXLevel
local Cosine = math.cos(Radian)*RandomZLevel
for _, EffectiveLight in pairs(EffectLight) do
EffectiveLight.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(Sine,0,Cosine)
end
end
end
end
game.Players.LocalPlayer.CharacterAdded:Connect(function()
Char = game.Players.LocalPlayer.Character
orbit(Char)
end)
#How do you make a part orbit around something?
1 messages · Page 1 of 1 (latest)
ive only recently learned CFrame
When i run the script it stays at the default position defined in line 15
idk how you get it to move with the player without a weld
@red gulch I found a forum page that does this: https://devforum.roblox.com/t/how-to-make-a-part-orbit-another-part/909378/6
here's the code:
local origin; --a cframe representing the origin of the rotation
local r = 10; --radius is commonly represented as a lowercase r in geometrical calculation
local rps = math.pi; --abbreviation for radians per second. note that pi radians equals 180 degrees
local orbiter; --reference to object doing the rotation. should be anchored for decent results
local angle = 0; --beginning angle in radians because radians are awesome
game:GetService'RunService'.Heartbeat:Connect(function(dt) --note that dt is short for deltatime, a value representing the time it took since the last frame for this frame to begin
angle = (angle + dt * rps) % (2 * math.pi); --add our rotation per second to our total angle after multiplying it by the deltatime to ensure the addition happens over the course of a second (if we didnt multiply this by the deltatime we would essentially be rotating by pi radians approximately every 30th of a second which is extremely fast). we should also ensure our angle value doesnt exceed 2pi radians (equivalent to 360 degrees) through modulus which isnt necessary but i believe to be good practice nonetheless
orbiter.CFrame = origin * CFrame.new(math.cos(angle) * r, 0, math.sin(angle) * r); --set the cframe of the orbiter every frame. our trigonometrical results should be multiplied by our radius to extend the distance according to the value. the way i arranged the trig here causes it to rotate on the y-plane but this can be changed pretty easily.
end)
Developer Forum | Roblox
Orbits are a rather vague concept due to various methods of CFrame manipulation. To form a generic circular orbit, we need to define a couple of constants: Origin; where does the orbit center around? Radius; how far away is the object doing the orbiting? Speed; how many radians does the object complete in one second? If this takes place on th...
ty i'll be reading it
the only actual code doing this is the one I sent so if you wanna know how it works just read the comments