// --------------------------------- // Portal Dimension Switching and Deformation // --------------------------------- void Update() { if (mainCamera.gameObject.layer != this.FromDimension().layer) { return; // don't transition if we are in different worlds. } Vector3 portalSize = meshFilter.mesh.bounds.size; bool shouldDeform = (Mathf.Pow(transform.InverseTransformDirection(mainCamera.transform.position - this.transform.position).z, 2) <= minimumDeformRangeSquared) && // z direction is close Mathf.Abs(transform.InverseTransformDirection(mainCamera.transform.position - this.transform.position).x) <= (portalSize.x * transform.lossyScale.x) / 2f && Mathf.Abs(transform.InverseTransformDirection(mainCamera.transform.position - this.transform.position).y) <= (portalSize.y * transform.lossyScale.y) / 2f; if (shouldDeform) { DeformPortalWithTransform(mainCamera.transform); } else if (isDeforming) { isDeforming = false; meshDeformer.ClearDeformingForce(); } CheckForTransitionObjects(); }