Initial Unity 6 scaffold for Cat Kirby Adventures.
Add Phase A greybox vertical slice: third-person movement, forest path, checkpoints, story triggers, and light ability gate.
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace KirbyAdventures
|
||||
{
|
||||
[RequireComponent(typeof(CharacterController))]
|
||||
public class PlayerMotor : MonoBehaviour
|
||||
{
|
||||
public float MoveSpeed = 6f;
|
||||
public float JumpHeight = 1.4f;
|
||||
public float Gravity = -22f;
|
||||
public float GroundStick = -2f;
|
||||
public Transform CameraTransform;
|
||||
public Transform YawPivot;
|
||||
|
||||
CharacterController _cc;
|
||||
Vector3 _velocity;
|
||||
bool _grounded;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_cc = GetComponent<CharacterController>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (GameFlow.Instance != null && (GameFlow.Instance.IsPaused || GameFlow.Instance.HasWon))
|
||||
return;
|
||||
|
||||
HandleRespawnInput();
|
||||
ReadMoveAndJump();
|
||||
}
|
||||
|
||||
void HandleRespawnInput()
|
||||
{
|
||||
var kb = Keyboard.current;
|
||||
if (kb != null && kb.rKey.wasPressedThisFrame)
|
||||
CheckpointSystem.Respawn(transform, _cc);
|
||||
}
|
||||
|
||||
void ReadMoveAndJump()
|
||||
{
|
||||
var kb = Keyboard.current;
|
||||
float h = 0f, v = 0f;
|
||||
if (kb != null)
|
||||
{
|
||||
if (kb.aKey.isPressed || kb.leftArrowKey.isPressed) h -= 1f;
|
||||
if (kb.dKey.isPressed || kb.rightArrowKey.isPressed) h += 1f;
|
||||
if (kb.sKey.isPressed || kb.downArrowKey.isPressed) v -= 1f;
|
||||
if (kb.wKey.isPressed || kb.upArrowKey.isPressed) v += 1f;
|
||||
}
|
||||
|
||||
_grounded = _cc.isGrounded;
|
||||
if (_grounded && _velocity.y < 0f)
|
||||
_velocity.y = GroundStick;
|
||||
|
||||
Vector3 forward = Vector3.forward;
|
||||
Vector3 right = Vector3.right;
|
||||
if (YawPivot != null)
|
||||
{
|
||||
forward = YawPivot.forward;
|
||||
right = YawPivot.right;
|
||||
}
|
||||
else if (CameraTransform != null)
|
||||
{
|
||||
forward = CameraTransform.forward;
|
||||
right = CameraTransform.right;
|
||||
}
|
||||
|
||||
forward.y = 0f;
|
||||
right.y = 0f;
|
||||
forward.Normalize();
|
||||
right.Normalize();
|
||||
|
||||
Vector3 move = (forward * v + right * h);
|
||||
if (move.sqrMagnitude > 1f) move.Normalize();
|
||||
|
||||
_cc.Move(move * MoveSpeed * Time.deltaTime);
|
||||
|
||||
if (kb != null && kb.spaceKey.wasPressedThisFrame && _grounded)
|
||||
_velocity.y = Mathf.Sqrt(JumpHeight * -2f * Gravity);
|
||||
|
||||
_velocity.y += Gravity * Time.deltaTime;
|
||||
_cc.Move(_velocity * Time.deltaTime);
|
||||
|
||||
if (move.sqrMagnitude > 0.01f)
|
||||
{
|
||||
var look = Quaternion.LookRotation(move, Vector3.up);
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, look, 12f * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace KirbyAdventures
|
||||
{
|
||||
/// <summary>
|
||||
/// Third-person follow camera with mouse look (avoids Cinemachine 3 API coupling).
|
||||
/// </summary>
|
||||
public class SimpleCameraFollow : MonoBehaviour
|
||||
{
|
||||
public Transform Target;
|
||||
public Transform YawPivot;
|
||||
public float Distance = 5.5f;
|
||||
public float Height = 1.6f;
|
||||
public float MouseSensitivity = 0.12f;
|
||||
public float MinPitch = -30f;
|
||||
public float MaxPitch = 55f;
|
||||
public float Smooth = 12f;
|
||||
|
||||
float _yaw;
|
||||
float _pitch = 12f;
|
||||
|
||||
public float Yaw => _yaw;
|
||||
public float Pitch => _pitch;
|
||||
|
||||
void Start()
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
if (YawPivot != null)
|
||||
_yaw = YawPivot.eulerAngles.y;
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
if (Target == null) return;
|
||||
if (GameFlow.Instance != null && (GameFlow.Instance.IsPaused || GameFlow.Instance.HasWon))
|
||||
return;
|
||||
|
||||
var mouse = Mouse.current;
|
||||
if (mouse != null)
|
||||
{
|
||||
var delta = mouse.delta.ReadValue();
|
||||
_yaw += delta.x * MouseSensitivity;
|
||||
_pitch -= delta.y * MouseSensitivity;
|
||||
_pitch = Mathf.Clamp(_pitch, MinPitch, MaxPitch);
|
||||
}
|
||||
|
||||
if (YawPivot != null)
|
||||
YawPivot.rotation = Quaternion.Euler(0f, _yaw, 0f);
|
||||
|
||||
var rot = Quaternion.Euler(_pitch, _yaw, 0f);
|
||||
var desired = Target.position + Vector3.up * Height + rot * (Vector3.back * Distance);
|
||||
transform.position = Vector3.Lerp(transform.position, desired, 1f - Mathf.Exp(-Smooth * Time.deltaTime));
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, rot, 1f - Mathf.Exp(-Smooth * Time.deltaTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user