Advertisement
DivineBlaze

Rotation Script

Sep 22nd, 2020
2,257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 0 0
  1. local TweenService = game:GetService("TweenService")
  2. local RunService = game:GetService("RunService")
  3.  
  4. local target = workspace:FindFirstChild("RotationPart")  -- The object to rotate around
  5. local camera = workspace.CurrentCamera
  6. camera.CameraType = Enum.CameraType.Scriptable
  7. local rotationAngle = Instance.new("NumberValue")
  8. local tweenComplete = false
  9.  
  10. local cameraOffset = Vector3.new(0, 10, 12)
  11. local rotationTime = 15  -- Time in seconds
  12. local rotationDegrees = 360
  13. local rotationRepeatCount = -1  -- Use -1 for infinite repeats
  14. local lookAtTarget = true  -- Whether the camera tilts to point directly at the target
  15.  
  16. local function updateCamera()
  17.     if not target then return end
  18.     camera.Focus = target.CFrame
  19.     local rotatedCFrame = CFrame.Angles(0, math.rad(rotationAngle.Value), 0)
  20.     rotatedCFrame = CFrame.new(target.Position) * rotatedCFrame
  21.     camera.CFrame = rotatedCFrame:ToWorldSpace(CFrame.new(cameraOffset))
  22.     if lookAtTarget == true then
  23.         camera.CFrame = CFrame.new(camera.CFrame.Position, target.Position)
  24.     end
  25. end
  26.  
  27. -- Set up and start rotation tween
  28. local tweenInfo = TweenInfo.new(rotationTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, rotationRepeatCount)
  29. local tween = TweenService:Create(rotationAngle, tweenInfo, {Value=rotationDegrees})
  30. tween.Completed:Connect(function()
  31.     tweenComplete = true
  32. end)
  33. tween:Play()
  34.  
  35. -- Update camera position while tween runs
  36. RunService.RenderStepped:Connect(function()
  37.     if tweenComplete == false then
  38.         updateCamera()
  39.     end
  40. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement