Advertisement
CluelessDev

Part orbiting another part

Feb 13th, 2022
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.60 KB | None | 0 0
  1. -- in StarterCharacterScripts
  2. local RunService = game:GetService("RunService")
  3.  
  4. local character = script.Parent
  5. local HRP = workspace.Pivot
  6. local orbitPart = workspace.Oribiter
  7. local pivot = workspace.Pivot
  8.  
  9. orbitPart.Anchored = true
  10.  
  11. local CYCLE_DURATION = 3
  12. local DISTANCE = 10
  13.  
  14. local i = 0
  15. RunService.Heartbeat:Connect(function(dt)
  16.     i = (i + dt/CYCLE_DURATION) % 1
  17.     local alpha = 2 * math.pi * i
  18.    
  19.     print(alpha)
  20.     orbitPart.CFrame = CFrame.Angles(0, alpha, 0)
  21.         * CFrame.new(0, 0, DISTANCE)
  22.         + HRP.Position
  23. end)
  24.  
  25. -- link
  26. -- https://devforum.roblox.com/t/part-to-orbit-around-player/1031587
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement