This commit is contained in:
2026-09-28 16:11:10 +02:00
parent fb630e5a7a
commit b0c6111d57
5 changed files with 92 additions and 8 deletions
+8 -6
View File
@@ -29,8 +29,8 @@ public sealed class PortalMeadow : MonoBehaviour
[SerializeField, Min(1)] private float boundsPadding = 128;
[Tooltip("Rendering layers of every generated PortalB renderer, so lights can be restricted to this world.")]
[SerializeField] private RenderingLayerMask renderingLayers = 1u;
[Tooltip("While not following the player, the bend is computed from this frame (e.g. the portal, looking along its forward axis) " +
"instead of the camera, so it stays aligned and still behind the portal.")]
[Tooltip("Entrance (e.g. the portal). While not following the player, the bend is computed from this frame (looking along its forward axis) " +
"instead of the camera, and the disk is centred on it, so everything stays aligned and still behind the portal.")]
[SerializeField] private Transform bendAnchor;
[Tooltip("Blend from the anchor frame to the camera once the player follows.")]
[SerializeField, Min(0)] private float bendFadeDuration = 1.5f;
@@ -65,7 +65,7 @@ public sealed class PortalMeadow : MonoBehaviour
public bool Endless => endless && Application.isPlaying;
/// <summary>Endless and currently recentering on the player (see SetFollowPlayer).</summary>
public bool Following => Endless && followPlayer;
public Vector3 SurfaceCenter => Following && capturedPlayer ? surfaceCenter : Center;
public Vector3 SurfaceCenter => Endless ? surfaceCenter : Center;
public void ConfigureRegion(Material target)
{
@@ -112,9 +112,11 @@ public sealed class PortalMeadow : MonoBehaviour
{
frameBlend = !Following ? 0 : bendFadeDuration > 0 ? Mathf.MoveTowards(frameBlend, 1, Time.deltaTime / bendFadeDuration) : 1;
surfaceCenter = Center;
if (Following && capturedPlayer)
// Before the crossing, the disk is already centred on the entrance, so following the player does not jump.
Transform focus = !Endless ? null : Following ? capturedPlayer : bendAnchor;
if (focus)
{
Vector3 p = transform.InverseTransformPoint(capturedPlayer.position);
Vector3 p = transform.InverseTransformPoint(focus.position);
surfaceCenter.x = p.x; surfaceCenter.z = p.z;
}
if (groundCollider) groundCollider.center = SurfaceCenter + Vector3.down * (colliderThickness * 0.5f);
@@ -129,7 +131,7 @@ public sealed class PortalMeadow : MonoBehaviour
{
Transform tile = tiles[i];
Vector3 p = tile.localPosition;
if (Following)
if (Endless)
{
p.x += Mathf.Floor((SurfaceCenter.x - p.x - tileSize.x * 0.5f + patchSize.x * 0.5f) / patchSize.x) * patchSize.x;
p.z += Mathf.Floor((SurfaceCenter.z - p.z - tileSize.y * 0.5f + patchSize.y * 0.5f) / patchSize.y) * patchSize.y;