Hi guys, Im making a parkour game and i want to add a cool camera effect where the players camera does a -360 rotation (like your doing a parkour roll) but im encountering a weird bug where once the rotation of the camera is negative, the camera bugs out and once the camera rotation is out of the negative rotation the bug stops. ive attached a video here (slowed the roll so you can see whats happening)
the script for the roll is attached here:
local function performCameraRoll(duration)
if isRolling then return end
isRolling = true
local camera = workspace.CurrentCamera
local originalCameraType = camera.CameraType
local startTime = tick()
local character = hrp.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid then
isRolling = false
return
end
local rollSpeed = humanoid.WalkSpeed * 0 -- this is just to stop the body velocity so you can see the camera roll
local initialForwardDirection = hrp.CFrame.LookVector
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = initialForwardDirection * rollSpeed
bodyVelocity.MaxForce = Vector3.new(10000, 0, 10000)
bodyVelocity.P = 1000
bodyVelocity.Parent = hrp
game.Lighting.Blur.Enabled = true
local initialHrpCFrame = hrp.CFrame
local initialCameraCFrame = camera.CFrame
local offset = initialHrpCFrame:Inverse() * initialCameraCFrame
camera.CameraType = Enum.CameraType.Scriptable
local BlurTween = game.TweenService:Create(game.Lighting.Blur, TweenInfo.new(duration/2, Enum.EasingStyle.Quad), {Size = 15})
local BlurTweenBack = game.TweenService:Create(game.Lighting.Blur, TweenInfo.new(duration/2, Enum.EasingStyle.Quad), {Size = 0})
local connection
connection = game:GetService("RunService").RenderStepped:Connect(function(dt)
local elapsed = tick() - startTime
if elapsed >= duration then
connection:Disconnect()
camera.CameraType = originalCameraType
if bodyVelocity then
bodyVelocity:Destroy()
end
isRolling = false
return
end
local alpha = elapsed / duration
local angle = math.rad(-360 * alpha)
local rollRotation = CFrame.Angles(angle, 0, 0)
camera.CFrame = hrp.CFrame * rollRotation
end)
BlurTween:Play()
BlurTween.Completed:Connect(function()
BlurTweenBack:Play()
BlurTweenBack.Completed:Connect(function()
game.Lighting.Blur.Enabled = false
end)
end)
end
if anyone can help me fix this it would be great!