From 886de49a894c47353753085baf4d3c97f1e8e076 Mon Sep 17 00:00:00 2001 From: ThatZeoMan <67521686+ThatZeoMan@users.noreply.github.com> Date: Tue, 16 Aug 2022 22:21:04 -0500 Subject: [PATCH 1/5] start work on screen shake --- Assets/Scripts/GameCamera.cs | 32 +++++++++++++++++++++++++++++++- Assets/Scripts/Minigames.cs | 8 ++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/GameCamera.cs b/Assets/Scripts/GameCamera.cs index b6082697..e81377fa 100644 --- a/Assets/Scripts/GameCamera.cs +++ b/Assets/Scripts/GameCamera.cs @@ -15,6 +15,7 @@ namespace HeavenStudio private List positionEvents = new List(); private List rotationEvents = new List(); private List scaleEvents = new List(); + private List shakeEvents = new List(); /** default cam position, for quick-resetting @@ -30,6 +31,7 @@ namespace HeavenStudio private static Vector3 position; private static Vector3 rotEluer; private static Vector3 scale; + private static Vector3 shakeResult; /** camera's last transformation @@ -38,6 +40,7 @@ namespace HeavenStudio private static Vector3 positionLast; private static Vector3 rotEluerLast; private static Vector3 scaleLast; + private static Vector3 shakeLast; /** transformations to apply *after* the global transform, @@ -89,20 +92,27 @@ namespace HeavenStudio rotationEvents = EventCaller.GetAllInGameManagerList("vfx", new string[] { "rotate camera" }); positionEvents.AddRange(EventCaller.GetAllInGameManagerList("gameManager", new string[] { "rotate camera" })); + //screen shake time baybee + + shakeEvents = EventCaller.GetAllInGameManagerList("vfx", new string[] { "screen shake" }); + + //scale (TODO) // scaleEvents = EventCaller.GetAllInGameManagerList("vfx", new string[] { "scale camera" }); UpdateCameraTranslate(); UpdateCameraRotate(); + SetShakeIntensity(); } private void Update() { UpdateCameraTranslate(); UpdateCameraRotate(); + SetShakeIntensity(); Camera cam = GetCamera(); - cam.transform.localPosition = position + additionalPosition; + cam.transform.localPosition = position + additionalPosition + shakeResult; cam.transform.eulerAngles = rotEluer + additionalRotEluer; cam.transform.localScale = Vector3.Scale(scale, additionalScale); } @@ -147,6 +157,26 @@ namespace HeavenStudio } } + //scren shake spaghetti + private void SetShakeIntensity() + { + foreach (var e in shakeEvents) + { + float prog = Conductor.instance.GetPositionFromBeat(e.beat, e.length); + if (prog >= 0f) + { + EasingFunction.Function func = EasingFunction.GetEasingFunction(e.ease); + float dx = func(positionLast.x, e.valA, Mathf.Min(prog, 1f)); + float dy = func(positionLast.y, e.valA, Mathf.Min(prog, 1f)); + shakeResult = new Vector3(dx, dy); + } + if (prog > 1f) + { + shakeLast = new Vector3(e.valA, e.valA); + } + } + } + public static void ResetTransforms() { position = defaultPosition; diff --git a/Assets/Scripts/Minigames.cs b/Assets/Scripts/Minigames.cs index cdb9132e..08d3ecda 100644 --- a/Assets/Scripts/Minigames.cs +++ b/Assets/Scripts/Minigames.cs @@ -332,6 +332,14 @@ namespace HeavenStudio new Param("ease", EasingFunction.Ease.Linear, "Ease") }, hidden: false ), + new GameAction("screen shake", delegate + { + //TODO: move cam + }, 1f, true, new List() + { + new Param("valA", new EntityTypes.Float(0, 50, 10), "Intensity") + } ), + new GameAction("move camera", delegate { //TODO: move cam From 52078ac4cd6d020855db09ea3946bdd380247ecc Mon Sep 17 00:00:00 2001 From: ThatZeoMan <67521686+ThatZeoMan@users.noreply.github.com> Date: Tue, 16 Aug 2022 22:24:39 -0500 Subject: [PATCH 2/5] Intensity input fully functional now time for, ugh, math. --- Assets/Scripts/GameCamera.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Assets/Scripts/GameCamera.cs b/Assets/Scripts/GameCamera.cs index e81377fa..0096a280 100644 --- a/Assets/Scripts/GameCamera.cs +++ b/Assets/Scripts/GameCamera.cs @@ -23,6 +23,7 @@ namespace HeavenStudio public static Vector3 defaultPosition = new Vector3(0, 0, -10); public static Vector3 defaultRotEluer = new Vector3(0, 0, 0); public static Vector3 defaultScale = new Vector3(16, 9, 1); + public static Vector3 defaultShake = new Vector3(0, 0, 0); /** camera's current transformation @@ -182,6 +183,7 @@ namespace HeavenStudio position = defaultPosition; rotEluer = defaultRotEluer; scale = defaultScale; + shakeResult = defaultShake; } public static void ResetAdditionalTransforms() From b4a029ba3f92f39f1b748580442797c74a49bc9a Mon Sep 17 00:00:00 2001 From: ThatZeoMan <67521686+ThatZeoMan@users.noreply.github.com> Date: Tue, 16 Aug 2022 22:30:22 -0500 Subject: [PATCH 3/5] automatically go back to old camera --- Assets/Scripts/GameCamera.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Scripts/GameCamera.cs b/Assets/Scripts/GameCamera.cs index 0096a280..eb91009c 100644 --- a/Assets/Scripts/GameCamera.cs +++ b/Assets/Scripts/GameCamera.cs @@ -173,7 +173,7 @@ namespace HeavenStudio } if (prog > 1f) { - shakeLast = new Vector3(e.valA, e.valA); + shakeResult = new Vector3(0, 0); } } } From a46b747898a6c046eda30102bbd4c906a3766e49 Mon Sep 17 00:00:00 2001 From: ThatZeoMan <67521686+ThatZeoMan@users.noreply.github.com> Date: Wed, 17 Aug 2022 11:31:55 -0500 Subject: [PATCH 4/5] something --- Assets/Scripts/GameCamera.cs | 4 +++- Assets/Scripts/Minigames.cs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/GameCamera.cs b/Assets/Scripts/GameCamera.cs index eb91009c..a87002cf 100644 --- a/Assets/Scripts/GameCamera.cs +++ b/Assets/Scripts/GameCamera.cs @@ -150,6 +150,7 @@ namespace HeavenStudio float dy = func(rotEluerLast.y, e.valB, Mathf.Min(prog, 1f)); float dz = func(rotEluerLast.z, e.valC, Mathf.Min(prog, 1f)); rotEluer = new Vector3(dx, dy, dz); + } if (prog > 1f) { @@ -169,7 +170,8 @@ namespace HeavenStudio EasingFunction.Function func = EasingFunction.GetEasingFunction(e.ease); float dx = func(positionLast.x, e.valA, Mathf.Min(prog, 1f)); float dy = func(positionLast.y, e.valA, Mathf.Min(prog, 1f)); - shakeResult = new Vector3(dx, dy); + shakeResult = new Vector3(Mathf.Sin(dx * 3.14159265f * 5f) * e.valA, Mathf.Sin(dy * 3.14159265f * 10f) * e.valA); + } if (prog > 1f) { diff --git a/Assets/Scripts/Minigames.cs b/Assets/Scripts/Minigames.cs index 08d3ecda..7fe4fb04 100644 --- a/Assets/Scripts/Minigames.cs +++ b/Assets/Scripts/Minigames.cs @@ -337,7 +337,7 @@ namespace HeavenStudio //TODO: move cam }, 1f, true, new List() { - new Param("valA", new EntityTypes.Float(0, 50, 10), "Intensity") + new Param("valA", new EntityTypes.Float(0, 10, 2), "Intensity") } ), new GameAction("move camera", delegate From 9356b058261cff4a5f9fd06564d9d7699461d7e9 Mon Sep 17 00:00:00 2001 From: ThatZeoMan <67521686+ThatZeoMan@users.noreply.github.com> Date: Wed, 17 Aug 2022 14:43:18 -0500 Subject: [PATCH 5/5] fully functional screen shake its a lil smooth at lower intensities but it works! lots of "complicated" "math" going on here. thanks for all the help, minenice! recommended settings - intensity: 2 length: 0.25 --- Assets/Scripts/GameCamera.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Scripts/GameCamera.cs b/Assets/Scripts/GameCamera.cs index a87002cf..3f98f1c5 100644 --- a/Assets/Scripts/GameCamera.cs +++ b/Assets/Scripts/GameCamera.cs @@ -170,7 +170,7 @@ namespace HeavenStudio EasingFunction.Function func = EasingFunction.GetEasingFunction(e.ease); float dx = func(positionLast.x, e.valA, Mathf.Min(prog, 1f)); float dy = func(positionLast.y, e.valA, Mathf.Min(prog, 1f)); - shakeResult = new Vector3(Mathf.Sin(dx * 3.14159265f * 5f) * e.valA, Mathf.Sin(dy * 3.14159265f * 10f) * e.valA); + shakeResult = new Vector3(Mathf.Cos(dx * e.length * 20f) * (e.valA / 2), Mathf.Cos(dy * e.length * 30f) * (e.valA / 2)); } if (prog > 1f)