I’m trying to make a cool camera rotation that looks like this around my player during a rebirth but the camera is shaky and laggy
Muscle Legends Rebirth :
My camera rotation :
Code of the rotation :
local UserInputService = game:GetService("UserInputService")
local CanRebirth = true
local char = script.Parent
local Camera = workspace.CurrentCamera
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if CanRebirth == true then
CanRebirth = false
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=17055625443"
local humanoid = char:WaitForChild("Humanoid")
local YourAnimationTrack = humanoid.Animator:LoadAnimation(animation)
YourAnimationTrack.Priority = Enum.AnimationPriority.Action2
YourAnimationTrack:Play()
--local characterCFrame = game.Players.LocalPlayer.Character.PrimaryPart.CFrame
--Camera.CameraType = Enum.CameraType.Scriptable
for i = 1, 360 do
Camera.CFrame = Camera.CFrame * CFrame.Angles(0, math.rad(i), 0)
task.wait(0.009)
end
CanRebirth = true
end
end
--wait(5)
end)
local TweenService = game:GetService("TweenService")
local Camera = workspace.CurrentCamera
local TweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear)
local TimesToSpin = 5
local function CreateTween(Rotation)
return TweenService:Create(Camera, TweenInfo, {CFrame = Camera.CFrame * CFrame.Angles(0, math.rad(Rotation), 0)})
end
local function Spin()
local Tweens = {
CreateTween(90),
CreateTween(180),
CreateTween(270),
CreateTween(0)
}
for i = 1, TimesToSpin do
for _, Tween in pairs(Tweens) do
Tween:Play()
Tween:Wait()
end
end
end
Spin()
I think lerping would be a nice way to make the rotation smoother I don’t know any other choice than lerping altough I don’t know how I would apply linear interpolation in my stuff
I changed the loop step and the end seems better than earlier
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local CanRebirth = true
local char = script.Parent
local Camera = workspace.CurrentCamera
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if CanRebirth == true then
CanRebirth = false
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=17055625443"
local humanoid = char:WaitForChild("Humanoid")
local YourAnimationTrack = humanoid.Animator:LoadAnimation(animation)
YourAnimationTrack.Priority = Enum.AnimationPriority.Action2
YourAnimationTrack:Play()
--local characterCFrame = game.Players.LocalPlayer.Character.PrimaryPart.CFrame
--Camera.CameraType = Enum.CameraType.Scriptable
for i = 5, 360, 5 do
Camera.CFrame = Camera.CFrame * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(0, 0, -5)
task.wait(0.1)
end
CanRebirth = true
end
end
--wait(5)
end)
Short script I came up with to rotate the camera around a CFrame with a speed, radius, and duration:
local RunService = game:GetService("RunService")
local function rotate(rpm : number, radius : number, center : CFrame, duration : number)
-- Does NOT yield!
-- Getting start time + camera
local start = tick()
local cam = workspace.CurrentCamera
-- Locking camera in place
cam.CameraType = Enum.CameraType.Scriptable
-- Getting the starting angle for the camera
local camLook = cam.CFrame.Position - center.Position
local angle = math.atan2(camLook.Z, camLook.X)
-- Calculating how much the camera should turn in one second
local degreesPerSecond = math.pi * 2 * rpm
-- Connecting to RunService for smoothness
local rotateConnection
rotateConnection = RunService.RenderStepped:Connect(function(deltaTime)
if duration < tick() - start then
-- Disconnect after a certain amount of time
rotateConnection:Disconnect()
cam.CameraType = Enum.CameraType.Custom
else
-- Rotate the angle, multiplying by deltaTime for consistent rotation speed
-- on different FPS values
angle = (angle + degreesPerSecond * deltaTime) % (math.pi * 2)
-- Get new CFrame for camera
local newCF = CFrame.lookAt(center.Position
+ math.sin(angle) * Vector3.zAxis * radius
+ math.cos(angle) * Vector3.xAxis * radius,
center.Position)
-- Move camera (using CFrame:Lerp for more smoothness)
cam.CFrame = cam.CFrame:Lerp(newCF, 0.75)
end
end)
end
-- Testing the rotate function
rotate(1, 15, workspace.CurrentCamera.Focus, 5)
I think I came up with my own solution but I’ll check yours to see how I can improve mine
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local CanRebirth = true
local char = script.Parent
local Camera = workspace.CurrentCamera
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if CanRebirth == true then
CanRebirth = false
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=17055625443"
local humanoid = char:WaitForChild("Humanoid")
local YourAnimationTrack = humanoid.Animator:LoadAnimation(animation)
YourAnimationTrack.Priority = Enum.AnimationPriority.Action2
YourAnimationTrack:Play()
--local characterCFrame = game.Players.LocalPlayer.Character.PrimaryPart.CFrame
--Camera.CameraType = Enum.CameraType.Scriptable
for j = 1, 95 do
for i = 1, 2 do
Camera.CFrame = Camera.CFrame * CFrame.fromEulerAnglesXYZ(0, i * .1, 0)
wait()
end
end
--[[for i = 5, 360, 5 do
Camera.CFrame = Camera.CFrame * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(0, 0, -5)
task.wait(0.1)
end]]
CanRebirth = true
end
end
--wait(5)
end)