From 69f57d30007b3b2cda6c2e950cbdb191b1d6f015 Mon Sep 17 00:00:00 2001 From: Philip White Date: Mon, 15 Nov 2021 16:48:04 +0000 Subject: [PATCH] Bug Fix Pasty Spawn Out of Bounds --- Unity-Files/Assets/Scripts/Gameplay/PastySpawn.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Unity-Files/Assets/Scripts/Gameplay/PastySpawn.cs b/Unity-Files/Assets/Scripts/Gameplay/PastySpawn.cs index 9c81e15..33f18d8 100644 --- a/Unity-Files/Assets/Scripts/Gameplay/PastySpawn.cs +++ b/Unity-Files/Assets/Scripts/Gameplay/PastySpawn.cs @@ -3,8 +3,12 @@ using DG.Tweening; public class PastySpawn : MonoBehaviour { + private float cameraBoundsOffset = -3f; + private Bounds mainCameraBounds; private void Start() { + mainCameraBounds = GetCameraBounds(Camera.main); + mainCameraBounds.Expand(cameraBoundsOffset); transform.DOMove(GetNewRandomPoint(), 1); } @@ -14,9 +18,7 @@ public class PastySpawn : MonoBehaviour if (isOutOfBounds(newPoint)) { - Bounds mainCameraBoundsOffset = GetCameraBounds(Camera.main); - mainCameraBoundsOffset.Expand(-1f); - newPoint = mainCameraBoundsOffset.ClosestPoint(this.transform.position); + newPoint = mainCameraBounds.ClosestPoint(newPoint); newPoint.Set(newPoint.x, newPoint.y, 0f); } return newPoint; @@ -24,11 +26,7 @@ public class PastySpawn : MonoBehaviour private bool isOutOfBounds(Vector3 targetPosition) { - Plane[] planes = GeometryUtility.CalculateFrustumPlanes(Camera.main); - if (GeometryUtility.TestPlanesAABB(planes, new Bounds(targetPosition, GetComponent().bounds.size))) - return false; - else - return true; + return mainCameraBounds.Intersects(new Bounds(targetPosition, GetComponent().bounds.size)) ? false : true; } private static Bounds GetCameraBounds(Camera camera)