Skip to content

Instantly share code, notes, and snippets.

@4igz

4igz/code.luau Secret

Created May 24, 2025 18:33
Show Gist options
  • Save 4igz/00a507f64b9bb6a397da4c6118d8f298 to your computer and use it in GitHub Desktop.
Save 4igz/00a507f64b9bb6a397da4c6118d8f298 to your computer and use it in GitHub Desktop.
elseif hasCutscene and camera ~= nil then
-- Makeshift cutscene. Basically just throws higher and sets camera subject to the treasure.
self.cutsceneActive = true
-- Prepare the treasure for the cutscene
local minYOffset = 4
local extentsY = existingModel:GetExtentsSize().Y
-- Ensure the treasure is below ground by using the negative of the offset
local yOffset = -math.max(extentsY, minYOffset)
local _cFrame = CFrame.new(origin)
local _vector3_1 = Vector3.new(0, yOffset, 0)
existingModel:PivotTo(_cFrame + _vector3_1)
for _, descendant in existingModel:GetDescendants() do
if descendant:IsA("BasePart") then
descendant.Anchored = true
descendant.CanCollide = false
end
end
-- Distance from treasure
local modelSize = existingModel:GetExtentsSize()
local cameraDistance = math.max(4.5, modelSize.Magnitude / 2 + 4.5)
local cameraAngle = 30
local cameraHeight = 10
local _exp_1 = TweenInfo.new(1.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local _object = {}
local _left = "Position"
local _vector3_2 = Vector3.new(0, 40, 0)
_object[_left] = origin + _vector3_2
local treasureTween = TweenService:Create(primaryPart, _exp_1, _object)
local angledPov = false
local angleRad = math.rad(cameraAngle)
local cameraOffset = if angledPov then Vector3.new(0, cameraHeight + math.sin(angleRad) * cameraDistance, math.cos(angleRad) * cameraDistance) else Vector3.new(0, cameraHeight + cameraDistance, 0)
local pos = primaryPart.Position + cameraOffset
local cleanMotion = cutsceneCameraMotion:start()
cutsceneCameraMotion:immediate(CFrame.new(pos))
local RENDERSTEP_ID = "CUTSCENE_ID"
local originalCameraType = camera.CameraType
-- Set last pos to prevent nan's
local focusCf = primaryPart.CFrame
local lastCameraCf = camera.CFrame
-- const originalCameraSubject = camera.CameraSubject;
-- camera.CFrame = character.GetPivot(); // Temp pos to not stream out pos
-- camera.Focus = character.GetPivot(); // Temp pos to not stream out pos
camera.CameraType = Enum.CameraType.Scriptable
RunService:BindToRenderStep(RENDERSTEP_ID, Enum.RenderPriority.Camera.Value - 1, function()
local cPrimaryPart = character.PrimaryPart or (character:FindFirstChild("HumanoidRootPart"))
local _characterCf = cPrimaryPart
if _characterCf ~= nil then
_characterCf = _characterCf.CFrame
end
local characterCf = _characterCf
local isNan = not isCframeValid(characterCf or focusCf)
focusCf = (if isNan then focusCf else characterCf) or focusCf
camera.Focus = focusCf
print("FOCUS:", focusCf)
if not primaryPart or not primaryPart.Parent or not cPrimaryPart then
camera.CameraType = Enum.CameraType.Custom
RunService:UnbindFromRenderStep(RENDERSTEP_ID)
return nil
end
local treasurePos = primaryPart.Position
local cameraOffset = if angledPov then Vector3.new(0, cameraHeight + math.sin(angleRad) * cameraDistance, math.cos(angleRad) * cameraDistance) else Vector3.new(0, cameraHeight + cameraDistance, 0)
local cameraPos = treasurePos + cameraOffset
-- Look at the treasure with a slight upward bias
if not isVector3Valid(cameraOffset) or not isVector3Valid(treasurePos) or not isVector3Valid(cameraPos) then
return nil
end
local newCf = CFrame.lookAt(cameraPos, treasurePos, Vector3.yAxis)
if not isCframeValid(newCf) then
camera.CFrame = lastCameraCf
return nil
end
camera.CFrame = newCf
lastCameraCf = newCf
print("CF:", camera.CFrame)
-- cutsceneCameraMotion.spring(
-- CFrame.lookAt(cameraPos, treasurePos, Vector3.yAxis),
-- springs.responsive,
-- );
end)
-- const cameraStepCleanup = cutsceneCameraMotion.onStep((v) => {
-- camera.CFrame = v;
-- });
digTrove:add(cleanMotion)
-- digTrove.add(cameraStepCleanup);
local sVfx = suspenseCutsceneVfx:Clone()
digTrove:add(sVfx)
sVfx:PivotTo(CFrame.new(origin))
sVfx.Parent = Workspace
task.wait(1.5)
if currentDigTrack then
currentDigTrack:Play()
currentDigTrack:GetMarkerReachedSignal(DIG_ANIMATION_MARKER):Once(function()
local endVfx = endCutsceneVfx:Clone()
endVfx:PivotTo(CFrame.new(origin))
endVfx.Parent = Workspace
digTrove:add(endVfx)
-- Signals.dig.Fire();
angledPov = true
treasureTween:Play()
end)
currentDigTrack.DidLoop:Connect(function()
local _result = currentDigTrack
if _result ~= nil then
_result:Stop()
end
end)
else
local endVfx = endCutsceneVfx:Clone()
endVfx:PivotTo(CFrame.new(origin))
endVfx.Parent = Workspace
digTrove:add(endVfx)
angledPov = true
treasureTween:Play()
end
treasureTween.Completed:Once(function()
-- Reset camera
RunService:UnbindFromRenderStep(RENDERSTEP_ID)
if camera then
camera.CameraType = originalCameraType
-- if (originalCameraSubject) {
-- camera.CameraSubject = originalCameraSubject;
-- }
end
cutsceneCameraMotion:stop()
existingModel:Destroy()
self.cutsceneActive = false
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment