diff --git a/scripts/camera_animation_clamped.lua b/scripts/camera_animation_clamped.lua index 86b7bf5b4..844ec5721 100644 --- a/scripts/camera_animation_clamped.lua +++ b/scripts/camera_animation_clamped.lua @@ -1,15 +1,30 @@ --- This script will play a camera animation chain from "cam0" -to "cam3" named camera proxies in the scene +-- This script will play a camera animation chain from "cam0" -to "camN" named camera proxies in the scene -- To use this, first place four cameras into the scene and name them cam0, cam1, cam2 and cam3, then press F8 to start -- The animation will repeat infinitely, but it will cut from last to first proxy at the end -- If no name is provided, this will return the main camera: local cam = GetCamera() +-- Camera speed overridable from outer scope too: +scriptableCameraSpeed = 0.4 + -- Animation state: local tt = 0.0 local play = false local rot = 0 +-- Gather camera proxies in the scene from "cam0" to "cam1", "cam2", ... "camN": +local proxies={} +local it = 0 +while true do + local cam = GetCamera("cam" .. it) + if(cam == nil) then + break + end + it = it + 1 + proxies[it] = cam +end + runProcess(function() while true do @@ -21,14 +36,14 @@ runProcess(function() end if(play) then -- Play animation: - local proxies = { GetCamera("cam0"), GetCamera("cam1"), GetCamera("cam2"), GetCamera("cam3") } + --local proxies = { GetCamera("cam0"), GetCamera("cam1"), GetCamera("cam2"), GetCamera("cam3") } local count = len(proxies) -- Place main camera on spline: cam.CatmullRom(proxies[math.clamp(rot - 1, 0, count - 1) + 1], proxies[math.clamp(rot, 0, count - 1) + 1], proxies[math.clamp(rot + 1, 0, count - 1) + 1], proxies[math.clamp(rot + 2, 0, count - 1) + 1], tt) -- Advance animation state: - tt = tt + 0.4 * getDeltaTime() + tt = tt + scriptableCameraSpeed * getDeltaTime() if(tt >= 1.0) then tt = 0.0 rot = rot + 1 diff --git a/scripts/camera_animation_repeat.lua b/scripts/camera_animation_repeat.lua index f0539da1d..e78da9479 100644 --- a/scripts/camera_animation_repeat.lua +++ b/scripts/camera_animation_repeat.lua @@ -1,15 +1,30 @@ --- This script will play a camera animation chain from "cam0" -to "cam3" named camera proxies in the scene +-- This script will play a camera animation chain from "cam0" -to "camN" named camera proxies in the scene -- To use this, first place four cameras into the scene and name them cam0, cam1, cam2 and cam3, then press F8 to start -- The animation will repeat infinitely, smoothly -- If no name is provided, this will return the main camera: local cam = GetCamera() +-- Camera speed overridable from outer scope too: +scriptableCameraSpeed = 0.4 + -- Animation state: local tt = 0.0 local play = false local rot = 0 +-- Gather camera proxies in the scene from "cam0" to "cam1", "cam2", ... "camN": +local proxies={} +local it = 0 +while true do + local cam = GetCamera("cam" .. it) + if(cam == nil) then + break + end + it = it + 1 + proxies[it] = cam +end + runProcess(function() while true do @@ -21,14 +36,14 @@ runProcess(function() end if(play) then -- Play animation: - local proxies = { GetCamera("cam0"), GetCamera("cam1"), GetCamera("cam2"), GetCamera("cam3") } + --local proxies = { GetCamera("cam0"), GetCamera("cam1"), GetCamera("cam2"), GetCamera("cam3") } local count = len(proxies) -- Place main camera on spline: cam.CatmullRom(proxies[(rot - 1) % count + 1], proxies[rot % count + 1], proxies[(rot + 1) % count + 1], proxies[(rot + 2) % count + 1], tt) -- Advance animation state: - tt = tt + 0.4 * getDeltaTime() + tt = tt + scriptableCameraSpeed * getDeltaTime() if(tt >= 1.0) then tt = 0.0 rot = rot + 1