feat: 탑다운 캐릭터 이동 플레이그라운드

- PlayerController: WASD/방향키 이동 + 진행방향 회전 (새 Input System)
- CameraFollow: 위에서 비스듬히 따라가는 카메라
- PlaygroundSetup: 바닥+캐릭터+카메라 자동 구성 메뉴

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
jklee
2026-06-14 20:00:45 +09:00
parent de5a40678e
commit 065355f63a
7 changed files with 173 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
using UnityEngine;
namespace SinoWms.Player
{
/// <summary>대상(캐릭터)을 위에서 비스듬히 따라다니는 탑다운 카메라.</summary>
public class CameraFollow : MonoBehaviour
{
[SerializeField] private Transform target;
[SerializeField] private Vector3 offset = new Vector3(0f, 12f, -8f);
[SerializeField] private float smooth = 8f;
public void SetTarget(Transform t) => target = t;
private void LateUpdate()
{
if (target == null) return;
Vector3 desired = target.position + offset;
transform.position = Vector3.Lerp(transform.position, desired, smooth * Time.deltaTime);
transform.LookAt(target.position);
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 378ab13c02a4c4074878e994d1593434
+55
View File
@@ -0,0 +1,55 @@
using UnityEngine;
using UnityEngine.InputSystem;
namespace SinoWms.Player
{
/// <summary>
/// 탑다운 캐릭터 이동. 새 Input System(Keyboard.current)으로 WASD/방향키 입력을 받아
/// XZ 평면을 이동하고, 진행 방향으로 부드럽게 회전한다.
/// </summary>
[RequireComponent(typeof(CharacterController))]
public class PlayerController : MonoBehaviour
{
[SerializeField] private float moveSpeed = 5f;
[SerializeField] private float turnSpeed = 12f;
[SerializeField] private float gravity = -20f;
private CharacterController _cc;
private float _verticalVelocity;
private void Awake()
{
_cc = GetComponent<CharacterController>();
}
private void Update()
{
var kb = Keyboard.current;
if (kb == null) return;
Vector2 input = Vector2.zero;
if (kb.wKey.isPressed || kb.upArrowKey.isPressed) input.y += 1f;
if (kb.sKey.isPressed || kb.downArrowKey.isPressed) input.y -= 1f;
if (kb.dKey.isPressed || kb.rightArrowKey.isPressed) input.x += 1f;
if (kb.aKey.isPressed || kb.leftArrowKey.isPressed) input.x -= 1f;
Vector3 move = new Vector3(input.x, 0f, input.y);
if (move.sqrMagnitude > 1f) move.Normalize();
// 중력 (바닥에 붙어있게)
if (_cc.isGrounded && _verticalVelocity < 0f) _verticalVelocity = -2f;
_verticalVelocity += gravity * Time.deltaTime;
Vector3 velocity = move * moveSpeed;
velocity.y = _verticalVelocity;
_cc.Move(velocity * Time.deltaTime);
// 진행 방향으로 회전
if (move.sqrMagnitude > 0.01f)
{
Quaternion target = Quaternion.LookRotation(move, Vector3.up);
transform.rotation = Quaternion.Slerp(transform.rotation, target, turnSpeed * Time.deltaTime);
}
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 00269464ac30a416992064182bd7186c