From c69fd8bf3d0978d18aeacfbd3bc87beea9bdf076 Mon Sep 17 00:00:00 2001 From: TobiMob <69400800+Tobi-Mob@users.noreply.github.com> Date: Fri, 22 Oct 2021 09:09:41 +0200 Subject: [PATCH] FollowCamera: * Use cached collider * Detect if TargetCollider was removed from TargetEntity --- Nez.Portable/ECS/Components/FollowCamera.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Nez.Portable/ECS/Components/FollowCamera.cs b/Nez.Portable/ECS/Components/FollowCamera.cs index ce8c50dc6..3b7af4c13 100644 --- a/Nez.Portable/ECS/Components/FollowCamera.cs +++ b/Nez.Portable/ECS/Components/FollowCamera.cs @@ -160,15 +160,15 @@ void UpdateFollow() } else { - // make sure we have a targetCollider for CameraWindow. If we dont bail out. - if (_targetCollider == null) + // make sure we have a targetCollider for CameraWindow attached to this Entity. If we dont bail out. + if (_targetCollider == null || _targetCollider.Entity != _targetEntity) { _targetCollider = _targetEntity.GetComponent(); if (_targetCollider == null) return; } - var targetBounds = _targetEntity.GetComponent().Bounds; + var targetBounds = _targetCollider.Bounds; if (!_worldSpaceDeadzone.Contains(targetBounds)) { // x-axis @@ -188,6 +188,12 @@ void UpdateFollow() public void Follow(Entity targetEntity, CameraStyle cameraStyle = CameraStyle.CameraWindow) { + if (targetEntity != _targetEntity) + { + // new entity -> invalidate cached collider + _targetCollider = null; + } + _targetEntity = targetEntity; _cameraStyle = cameraStyle; var cameraBounds = Camera.Bounds;