Persist player and third-person camera state across sessions
Add player position/rotation/wall-climb persistence and camera orbit (yaw/pitch/radius) persistence, auto-saved on quit/play-stop and auto-loaded on start. Also includes the wall-climb fixes (directional top-out, base detach on push-away). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
fa7082817e
commit
cda1373979
8 files changed
+340
-16
No files matched your search
@@ -27,7 +27,7 @@ using UnityEngine.InputSystem;
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(CharacterController))]
|
||||
[DisallowMultipleComponent]
|
||||
public class PlayerCharacterController : MonoBehaviour
|
||||
public partial class PlayerCharacterController : MonoBehaviour
|
||||
{
|
||||
[Header("Movement")]
|
||||
[Tooltip("Horizontal movement speed (units/second).")]
|
||||
@@ -428,7 +428,10 @@ public class PlayerCharacterController : MonoBehaviour
|
||||
if (found && !onCeiling && _climbLeftGround
|
||||
&& Vector3.Angle(_wallNormal, Vector3.up) < wallMinAngle)
|
||||
{
|
||||
TopOutDetach(); // climbed face flattened into walkable: hop over the lip instead of dropping onto the steep section below
|
||||
// Hop over the lip only when actually moving up onto the flattened face (a real
|
||||
// top-out); if we reached it going down, just step off cleanly with no hop.
|
||||
if (v > 0f) TopOutDetach();
|
||||
else ExitWallClimb();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -530,17 +533,27 @@ public class PlayerCharacterController : MonoBehaviour
|
||||
|
||||
_controller.Move(velocity * dt);
|
||||
|
||||
// Reaching walkable ground detaches and drops back to normal grounded movement. Gated
|
||||
// on having left the ground first, so grabbing a wall at its base (still grounded)
|
||||
// doesn't instantly detach. We test for walkable ground under the feet rather than
|
||||
// trusting isGrounded: the standoff correction can lift the capsule just off the
|
||||
// surface, so at a slope's top isGrounded stays false and the old check never fired.
|
||||
// Reaching walkable ground detaches back to normal grounded movement. The top-out hop
|
||||
// (carry over the lip) fires ONLY when topping out upward over an edge (v > 0). Arriving
|
||||
// at the floor by descending, OR pressing down/away (S, v < 0) at the wall's base while
|
||||
// grounded, just lets go cleanly with no hop -- the latter is the only detach path that
|
||||
// doesn't require having left the ground first, so a wall grabbed at its base can be
|
||||
// released by pressing away. We test walkable ground under the feet rather than trusting
|
||||
// isGrounded: the standoff correction can lift the capsule just off the surface, so at a
|
||||
// slope's top isGrounded stays false and the old check never fired.
|
||||
bool onWalkableGround = _controller.isGrounded || WalkableGroundBelow();
|
||||
if (!onWalkableGround)
|
||||
_climbLeftGround = true;
|
||||
else if (_climbLeftGround)
|
||||
{
|
||||
TopOutDetach(); // reached walkable ground at the top: hop up onto it instead of sliding back down the face
|
||||
_climbLeftGround = true;
|
||||
}
|
||||
else if (_climbLeftGround && v > 0f)
|
||||
{
|
||||
TopOutDetach(); // topped out upward onto walkable ground: hop over the lip (holding W carries on)
|
||||
return;
|
||||
}
|
||||
else if (_climbLeftGround || v < 0f)
|
||||
{
|
||||
ExitWallClimb(); // descended to the floor, or pulling down/away at the base: let go, no hop
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user