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;