์ฝ˜ํ…์ธ  ๋Œ€ํ‘œ ์ด๋ฏธ์ง€ - ๐ŸŽฎ Unity 3D ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค ์†Œ์Šค์ฝ”๋“œ ์™„๋ฒฝ ๊ฐ€์ด๋“œ

๐ŸŽฎ Unity 3D ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค ์†Œ์Šค์ฝ”๋“œ ์™„๋ฒฝ ๊ฐ€์ด๋“œ

๊ฒŒ์ž„ ๊ฐœ๋ฐœ์˜ ํ•ต์‹ฌ! ์บ๋ฆญํ„ฐ๋ฅผ ์ž์œ ์ž์žฌ๋กœ ์›€์ง์ด๋Š” ๋งˆ๋ฒ• ๊ฐ™์€ ์ฝ”๋“œ ์„ธ๊ณ„๋กœ ์ดˆ๋Œ€ํ•ฉ๋‹ˆ๋‹ค โœจ

์•ˆ๋…•! ์˜ค๋Š˜์€ Unity๋กœ ๊ฒŒ์ž„ ๊ฐœ๋ฐœํ•  ๋•Œ ๊ฐ€์žฅ ๊ธฐ๋ณธ์ด๋ฉด์„œ๋„ ๊ฐ€์žฅ ์ค‘์š”ํ•œ 3D ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค์— ๋Œ€ํ•ด ์ด์•ผ๊ธฐํ•ด๋ณผ๊ฒŒ. ๐ŸŽฏ ๊ฒŒ์ž„์„ ๋งŒ๋“ค๋‹ค ๋ณด๋ฉด ์บ๋ฆญํ„ฐ๊ฐ€ ์ œ๋Œ€๋กœ ์›€์ง์ด์ง€ ์•Š์•„์„œ ๋‹ต๋‹ตํ–ˆ๋˜ ๊ฒฝํ—˜, ๋‹ค๋“ค ์žˆ์ง€? ๊ฑฑ์ • ๋งˆ! ์˜ค๋Š˜ ์ด ๊ธ€์„ ๋‹ค ์ฝ๊ณ  ๋‚˜๋ฉด ๋„ˆ๋„ ์บ๋ฆญํ„ฐ๋ฅผ ์ž์œ ์ž์žฌ๋กœ ์กฐ์ข…ํ•˜๋Š” ๋งˆ๋ฒ•์‚ฌ๊ฐ€ ๋  ์ˆ˜ ์žˆ์„ ๊ฑฐ์•ผ! ๐Ÿง™โ€โ™‚๏ธ

Character Controller Unity 3D Game Development

๐ŸŽฌ ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค์˜ ๊ธฐ์ดˆ: ์™œ ์ค‘์š”ํ• ๊นŒ?

๊ฒŒ์ž„์—์„œ ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค์€ ํ”Œ๋ ˆ์ด์–ด์™€ ๊ฒŒ์ž„ ์„ธ๊ณ„๋ฅผ ์—ฐ๊ฒฐํ•˜๋Š” ๊ฐ€์žฅ ์ง์ ‘์ ์ธ ์ธํ„ฐํŽ˜์ด์Šค์•ผ. ์•„๋ฌด๋ฆฌ ๊ทธ๋ž˜ํ”ฝ์ด ํ™”๋ คํ•˜๊ณ  ์Šคํ† ๋ฆฌ๊ฐ€ ์ข‹์•„๋„, ์บ๋ฆญํ„ฐ๊ฐ€ ๋‚ด ์˜๋„๋Œ€๋กœ ์›€์ง์ด์ง€ ์•Š์œผ๋ฉด ๊ฒŒ์ž„์€ ์žฌ๋ฏธ์—†์–ด์ง€๊ฑฐ๋“ . ๐Ÿ˜…

๐Ÿ’ก ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค์ด ์ค‘์š”ํ•œ ์ด์œ  1. ํ”Œ๋ ˆ์ด์–ด ๊ฒฝํ—˜์˜ ํ•ต์‹ฌ - ๊ฒŒ์ž„์˜ ์ฒซ์ธ์ƒ์„ ๊ฒฐ์ •ํ•ด
2. ๊ฒŒ์ž„ ์žฅ๋ฅด์˜ ์ •์ฒด์„ฑ - FPS, TPS, RPG๋งˆ๋‹ค ๋‹ค๋ฅธ ๋А๋‚Œ์„ ์ค˜
3. ๋ฌผ๋ฆฌ ๋ฒ•์น™๊ณผ์˜ ์กฐํ™” - ํ˜„์‹ค๊ฐ ์žˆ๋Š” ์›€์ง์ž„์ด ๋ชฐ์ž…๋„๋ฅผ ๋†’์—ฌ
4. ๋ฐ˜์‘์„ฑ๊ณผ ์ •ํ™•์„ฑ - ์ž…๋ ฅ์— ๋Œ€ํ•œ ์ฆ‰๊ฐ์ ์ธ ํ”ผ๋“œ๋ฐฑ์ด ์ค‘์š”ํ•ด

๐Ÿ› ๏ธ Unity์˜ ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค ์‹œ์Šคํ…œ ์ดํ•ดํ•˜๊ธฐ

Unity์—์„œ ์บ๋ฆญํ„ฐ๋ฅผ ์›€์ง์ด๋Š” ๋ฐฉ๋ฒ•์€ ํฌ๊ฒŒ ์„ธ ๊ฐ€์ง€๊ฐ€ ์žˆ์–ด. ๊ฐ๊ฐ์˜ ์žฅ๋‹จ์ ์„ ์•Œ์•„๋ณด์ž! ๐Ÿ”

1๏ธโƒฃ Transform ์ง์ ‘ ์กฐ์ž‘ ๋ฐฉ์‹

๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ธ ๋ฐฉ๋ฒ•์ด์•ผ. Transform ์ปดํฌ๋„ŒํŠธ์˜ position์„ ์ง์ ‘ ๋ณ€๊ฒฝํ•˜๋Š” ๊ฑฐ์ง€. ๊ฐ„๋‹จํ•˜์ง€๋งŒ ๋ฌผ๋ฆฌ ์—”์ง„์„ ๋ฌด์‹œํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ถฉ๋Œ ์ฒ˜๋ฆฌ๊ฐ€ ์ œ๋Œ€๋กœ ์•ˆ ๋  ์ˆ˜ ์žˆ์–ด.

// Transform ์ง์ ‘ ์กฐ์ž‘ ์˜ˆ์ œ
void Update()
{
    float moveSpeed = 5f;
    float horizontal = Input.GetAxis("Horizontal");
    float vertical = Input.GetAxis("Vertical");
    
    Vector3 movement = new Vector3(horizontal, 0f, vertical);
    transform.position += movement * moveSpeed * Time.deltaTime;
}
๐ŸŒŸ Tip: ์ด ๋ฐฉ์‹์€ ํ”„๋กœํ† ํƒ€์ดํ•‘์ด๋‚˜ ๊ฐ„๋‹จํ•œ ํ…Œ์ŠคํŠธ์šฉ์œผ๋กœ ์ข‹์•„. ํ•˜์ง€๋งŒ ์‹ค์ œ ๊ฒŒ์ž„์—์„œ๋Š” ๋ฌผ๋ฆฌ ์ถฉ๋Œ์ด ํ•„์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ์ถ”์ฒœํ•ด!

2๏ธโƒฃ Rigidbody ๋ฌผ๋ฆฌ ๊ธฐ๋ฐ˜ ๋ฐฉ์‹

Rigidbody ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด Unity์˜ ๋ฌผ๋ฆฌ ์—”์ง„์„ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ์–ด. ์ค‘๋ ฅ, ๋งˆ์ฐฐ, ์ถฉ๋Œ ๋“ฑ์ด ์ž๋™์œผ๋กœ ์ฒ˜๋ฆฌ๋˜์ง€! ๐ŸŽฒ

// Rigidbody๋ฅผ ์‚ฌ์šฉํ•œ ์บ๋ฆญํ„ฐ ์ด๋™
public class RigidbodyController : MonoBehaviour
{
    private Rigidbody rb;
    public float moveSpeed = 5f;
    public float jumpForce = 7f;
    
    void Start()
    {
        rb = GetComponent<Rigidbody>();
        // ํšŒ์ „ ๊ณ ์ • (์บ๋ฆญํ„ฐ๊ฐ€ ๋„˜์–ด์ง€์ง€ ์•Š๋„๋ก)
        rb.freezeRotation = true;
    }
    
    void FixedUpdate()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical = Input.GetAxis("Vertical");
        
        Vector3 movement = new Vector3(horizontal, 0f, vertical).normalized;
        rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
        
        // ์ ํ”„
        if (Input.GetButtonDown("Jump") && IsGrounded())
        {
            rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
        }
    }
    
    bool IsGrounded()
    {
        return Physics.Raycast(transform.position, Vector3.down, 1.1f);
    }
}
โš ๏ธ ์ฃผ์˜์‚ฌํ•ญ: Rigidbody๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ๋Š” ๋ฐ˜๋“œ์‹œ FixedUpdate()์—์„œ ๋ฌผ๋ฆฌ ์—ฐ์‚ฐ์„ ํ•ด์•ผ ํ•ด. Update()์—์„œ ํ•˜๋ฉด ํ”„๋ ˆ์ž„์— ๋”ฐ๋ผ ์›€์ง์ž„์ด ๋ถˆ๊ทœ์น™ํ•ด์งˆ ์ˆ˜ ์žˆ๊ฑฐ๋“ !

3๏ธโƒฃ Character Controller ์ปดํฌ๋„ŒํŠธ ๋ฐฉ์‹

Unity๊ฐ€ ์ œ๊ณตํ•˜๋Š” Character Controller๋Š” ์บ๋ฆญํ„ฐ ์ด๋™์„ ์œ„ํ•ด ํŠน๋ณ„ํžˆ ์„ค๊ณ„๋œ ์ปดํฌ๋„ŒํŠธ์•ผ. Rigidbody๋ณด๋‹ค ๊ฐ€๋ณ๊ณ , ๊ณ„๋‹จ ์˜ค๋ฅด๊ธฐ๋‚˜ ๊ฒฝ์‚ฌ๋ฉด ์ฒ˜๋ฆฌ๊ฐ€ ์ž๋™์œผ๋กœ ๋ผ์„œ ๋งŽ์ด ์‚ฌ์šฉํ•ด! ๐ŸŽฏ

// Character Controller๋ฅผ ์‚ฌ์šฉํ•œ ๊ธฐ๋ณธ ์ด๋™
public class CharacterMovement : MonoBehaviour
{
    private CharacterController controller;
    public float moveSpeed = 6f;
    public float gravity = -9.81f;
    public float jumpHeight = 2f;
    
    private Vector3 velocity;
    private bool isGrounded;
    
    void Start()
    {
        controller = GetComponent<CharacterController>();
    }
    
    void Update()
    {
        // ๋•…์— ๋‹ฟ์•˜๋Š”์ง€ ํ™•์ธ
        isGrounded = controller.isGrounded;
        if (isGrounded && velocity.y < 0)
        {
            velocity.y = -2f; // ์•ฝ๊ฐ„์˜ ํ•˜ํ–ฅ ํž˜์œผ๋กœ ์ ‘์ง€ ์œ ์ง€
        }
        
        // ์ด๋™ ์ž…๋ ฅ
        float horizontal = Input.GetAxis("Horizontal");
        float vertical = Input.GetAxis("Vertical");
        
        Vector3 move = transform.right * horizontal + transform.forward * vertical;
        controller.Move(move * moveSpeed * Time.deltaTime);
        
        // ์ ํ”„
        if (Input.GetButtonDown("Jump") && isGrounded)
        {
            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
        }
        
        // ์ค‘๋ ฅ ์ ์šฉ
        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);
    }
}

๐ŸŽจ ์‹ค์ „ ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ ๊ตฌํ˜„ํ•˜๊ธฐ

์ด์ œ ๋ณธ๊ฒฉ์ ์œผ๋กœ ์‹ค์ „์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์™„์„ฑ๋„ ๋†’์€ ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ๋งŒ๋“ค์–ด๋ณผ๊ฒŒ! ๊ฑท๊ธฐ, ๋‹ฌ๋ฆฌ๊ธฐ, ์ ํ”„, ์นด๋ฉ”๋ผ ํšŒ์ „๊นŒ์ง€ ๋ชจ๋‘ ํฌํ•จ๋œ ์ฝ”๋“œ์•ผ. ๐Ÿ˜Ž

Input System โŒจ๏ธ WASD / Arrow Keys Space: Jump Shift: Sprint Mouse: Look Around Controller Logic Movement Calculation Physics Application Animation Update Camera Control Character Output

๐Ÿš€ ๊ณ ๊ธ‰ ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ ์ „์ฒด ์ฝ”๋“œ

using UnityEngine;

public class AdvancedCharacterController : MonoBehaviour
{
    [Header("Movement Settings")]
    public float walkSpeed = 4f;
    public float sprintSpeed = 8f;
    public float crouchSpeed = 2f;
    public float jumpHeight = 2.5f;
    public float gravity = -15f;
    
    [Header("Camera Settings")]
    public Transform cameraTransform;
    public float mouseSensitivity = 2f;
    public float maxLookAngle = 80f;
    
    [Header("Ground Check")]
    public Transform groundCheck;
    public float groundDistance = 0.4f;
    public LayerMask groundMask;
    
    // Private variables
    private CharacterController controller;
    private Vector3 velocity;
    private bool isGrounded;
    private float currentSpeed;
    private float cameraPitch = 0f;
    
    void Start()
    {
        controller = GetComponent<CharacterController>();
        
        // ๋งˆ์šฐ์Šค ์ปค์„œ ์ˆจ๊ธฐ๊ธฐ
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
        
        // ์นด๋ฉ”๋ผ๊ฐ€ ์—†์œผ๋ฉด ๋ฉ”์ธ ์นด๋ฉ”๋ผ ์ฐพ๊ธฐ
        if (cameraTransform == null)
        {
            cameraTransform = Camera.main.transform;
        }
    }
    
    void Update()
    {
        HandleGroundCheck();
        HandleMovement();
        HandleJump();
        HandleCamera();
    }
    
    void HandleGroundCheck()
    {
        // ๋•…์— ๋‹ฟ์•˜๋Š”์ง€ ํ™•์ธ
        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
        
        if (isGrounded && velocity.y < 0)
        {
            velocity.y = -2f; // ์ ‘์ง€ ์ƒํƒœ ์œ ์ง€
        }
    }
    
    void HandleMovement()
    {
        // ์ž…๋ ฅ ๋ฐ›๊ธฐ
        float horizontal = Input.GetAxis("Horizontal");
        float vertical = Input.GetAxis("Vertical");
        
        // ์ด๋™ ์†๋„ ๊ฒฐ์ •
        if (Input.GetKey(KeyCode.LeftShift))
        {
            currentSpeed = sprintSpeed;
        }
        else if (Input.GetKey(KeyCode.LeftControl))
        {
            currentSpeed = crouchSpeed;
        }
        else
        {
            currentSpeed = walkSpeed;
        }
        
        // ์ด๋™ ๋ฐฉํ–ฅ ๊ณ„์‚ฐ (์นด๋ฉ”๋ผ ๊ธฐ์ค€)
        Vector3 move = transform.right * horizontal + transform.forward * vertical;
        
        // ๋Œ€๊ฐ์„  ์ด๋™ ์‹œ ์†๋„ ์ •๊ทœํ™”
        if (move.magnitude > 1f)
        {
            move.Normalize();
        }
        
        // ์บ๋ฆญํ„ฐ ์ด๋™
        controller.Move(move * currentSpeed * Time.deltaTime);
        
        // ์ค‘๋ ฅ ์ ์šฉ
        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);
    }
    
    void HandleJump()
    {
        if (Input.GetButtonDown("Jump") && isGrounded)
        {
            // ์ ํ”„ ๊ณต์‹: v = sqrt(h * -2 * g)
            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
        }
    }
    
    void HandleCamera()
    {
        // ๋งˆ์šฐ์Šค ์ž…๋ ฅ
        float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity;
        float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity;
        
        // ์ขŒ์šฐ ํšŒ์ „ (Y์ถ•)
        transform.Rotate(Vector3.up * mouseX);
        
        // ์ƒํ•˜ ํšŒ์ „ (X์ถ•) - ์นด๋ฉ”๋ผ๋งŒ
        cameraPitch -= mouseY;
        cameraPitch = Mathf.Clamp(cameraPitch, -maxLookAngle, maxLookAngle);
        cameraTransform.localRotation = Quaternion.Euler(cameraPitch, 0f, 0f);
    }
    
    // ํ˜„์žฌ ์ด๋™ ์†๋„ ๋ฐ˜ํ™˜ (์• ๋‹ˆ๋ฉ”์ด์…˜์šฉ)
    public float GetCurrentSpeed()
    {
        Vector3 horizontalVelocity = new Vector3(controller.velocity.x, 0f, controller.velocity.z);
        return horizontalVelocity.magnitude;
    }
    
    // ์ ํ”„ ์ค‘์ธ์ง€ ํ™•์ธ (์• ๋‹ˆ๋ฉ”์ด์…˜์šฉ)
    public bool IsJumping()
    {
        return !isGrounded;
    }
}
๐Ÿ“‹ ์ฝ”๋“œ ์„ค๋ช…

์ด ์ฝ”๋“œ๋Š” ์‹ค์ œ ๊ฒŒ์ž„์—์„œ ๋ฐ”๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ˆ˜์ค€์˜ ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ์•ผ. ์ฃผ์š” ๊ธฐ๋Šฅ์„ ์‚ดํŽด๋ณด๋ฉด:

โ€ข ๋‹ค์–‘ํ•œ ์ด๋™ ๋ชจ๋“œ: ๊ฑท๊ธฐ, ๋‹ฌ๋ฆฌ๊ธฐ, ์›…ํฌ๋ฆฌ๊ธฐ๋ฅผ Shift์™€ Ctrl ํ‚ค๋กœ ์ „ํ™˜
โ€ข ๋ฌผ๋ฆฌ ๊ธฐ๋ฐ˜ ์ ํ”„: ์ž์—ฐ์Šค๋Ÿฌ์šด ํฌ๋ฌผ์„  ๊ถค์ ์˜ ์ ํ”„ ๊ตฌํ˜„
โ€ข 1์ธ์นญ ์นด๋ฉ”๋ผ: ๋งˆ์šฐ์Šค๋กœ ์ž์œ ๋กœ์šด ์‹œ์  ์ „ํ™˜
โ€ข ์ ‘์ง€ ๊ฐ์ง€: Physics.CheckSphere๋กœ ์ •ํ™•ํ•œ ๋•… ๊ฐ์ง€
โ€ข ์• ๋‹ˆ๋ฉ”์ด์…˜ ์—ฐ๋™: ํ˜„์žฌ ์†๋„์™€ ์ ํ”„ ์ƒํƒœ๋ฅผ ์™ธ๋ถ€์—์„œ ์ฐธ์กฐ ๊ฐ€๋Šฅ

๐ŸŽฏ ์นด๋ฉ”๋ผ ์‹œ์Šคํ…œ ๊ตฌํ˜„ํ•˜๊ธฐ

์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋งŒํผ ์ค‘์š”ํ•œ ๊ฒŒ ์นด๋ฉ”๋ผ์•ผ! 3์ธ์นญ ์นด๋ฉ”๋ผ๋ฅผ ๋งŒ๋“ค์–ด๋ณผ๊ฒŒ. ๐ŸŽฅ

// 3์ธ์นญ ์นด๋ฉ”๋ผ ์ปจํŠธ๋กค๋Ÿฌ
public class ThirdPersonCamera : MonoBehaviour
{
    [Header("Target Settings")]
    public Transform target; // ์บ๋ฆญํ„ฐ
    public Vector3 offset = new Vector3(0f, 2f, -5f);
    
    [Header("Camera Settings")]
    public float rotationSpeed = 5f;
    public float smoothSpeed = 10f;
    public float minDistance = 2f;
    public float maxDistance = 10f;
    public float zoomSpeed = 2f;
    
    [Header("Collision")]
    public LayerMask collisionLayers;
    public float collisionOffset = 0.3f;
    
    private float currentDistance;
    private float desiredDistance;
    private float currentRotationX = 0f;
    private float currentRotationY = 0f;
    
    void Start()
    {
        currentDistance = offset.magnitude;
        desiredDistance = currentDistance;
        
        // ์ดˆ๊ธฐ ํšŒ์ „๊ฐ’ ์„ค์ •
        Vector3 angles = transform.eulerAngles;
        currentRotationX = angles.y;
        currentRotationY = angles.x;
    }
    
    void LateUpdate()
    {
        if (target == null) return;
        
        HandleRotation();
        HandleZoom();
        HandlePosition();
        HandleCollision();
    }
    
    void HandleRotation()
    {
        // ๋งˆ์šฐ์Šค ์ž…๋ ฅ
        if (Input.GetMouseButton(1)) // ์šฐํด๋ฆญ ์‹œ์—๋งŒ ํšŒ์ „
        {
            currentRotationX += Input.GetAxis("Mouse X") * rotationSpeed;
            currentRotationY -= Input.GetAxis("Mouse Y") * rotationSpeed;
            currentRotationY = Mathf.Clamp(currentRotationY, -30f, 60f);
        }
    }
    
    void HandleZoom()
    {
        // ๋งˆ์šฐ์Šค ํœ ๋กœ ์คŒ
        float scroll = Input.GetAxis("Mouse ScrollWheel");
        desiredDistance -= scroll * zoomSpeed;
        desiredDistance = Mathf.Clamp(desiredDistance, minDistance, maxDistance);
        
        currentDistance = Mathf.Lerp(currentDistance, desiredDistance, Time.deltaTime * smoothSpeed);
    }
    
    void HandlePosition()
    {
        // ํšŒ์ „ ์ ์šฉ
        Quaternion rotation = Quaternion.Euler(currentRotationY, currentRotationX, 0f);
        
        // ๋ชฉํ‘œ ์œ„์น˜ ๊ณ„์‚ฐ
        Vector3 direction = rotation * -Vector3.forward;
        Vector3 desiredPosition = target.position + direction * currentDistance + Vector3.up * offset.y;
        
        // ๋ถ€๋“œ๋Ÿฌ์šด ์ด๋™
        transform.position = Vector3.Lerp(transform.position, desiredPosition, Time.deltaTime * smoothSpeed);
        transform.LookAt(target.position + Vector3.up * offset.y);
    }
    
    void HandleCollision()
    {
        // ์นด๋ฉ”๋ผ์™€ ์บ๋ฆญํ„ฐ ์‚ฌ์ด์— ์žฅ์• ๋ฌผ์ด ์žˆ๋Š”์ง€ ํ™•์ธ
        Vector3 targetPosition = target.position + Vector3.up * offset.y;
        Vector3 direction = transform.position - targetPosition;
        
        RaycastHit hit;
        if (Physics.Raycast(targetPosition, direction.normalized, out hit, currentDistance, collisionLayers))
        {
            // ์žฅ์• ๋ฌผ์ด ์žˆ์œผ๋ฉด ์นด๋ฉ”๋ผ๋ฅผ ์•ž์œผ๋กœ ๋‹น๊น€
            float distance = hit.distance - collisionOffset;
            transform.position = targetPosition + direction.normalized * distance;
        }
    }
}
๐ŸŽฌ ์นด๋ฉ”๋ผ ํŒ: 3์ธ์นญ ์นด๋ฉ”๋ผ๋Š” LateUpdate()์—์„œ ์—…๋ฐ์ดํŠธํ•ด์•ผ ํ•ด. ๊ทธ๋ž˜์•ผ ์บ๋ฆญํ„ฐ๊ฐ€ ๋จผ์ € ์›€์ง์ด๊ณ  ๋‚˜์„œ ์นด๋ฉ”๋ผ๊ฐ€ ๋”ฐ๋ผ๊ฐ€์„œ ๋–จ๋ฆผ ํ˜„์ƒ์ด ์—†์–ด์ ธ!

โšก ์• ๋‹ˆ๋ฉ”์ด์…˜ ์—ฐ๋™ํ•˜๊ธฐ

์บ๋ฆญํ„ฐ๊ฐ€ ์›€์ง์ผ ๋•Œ ์• ๋‹ˆ๋ฉ”์ด์…˜๋„ ๊ฐ™์ด ์žฌ์ƒ๋˜์–ด์•ผ ์ž์—ฐ์Šค๋Ÿฝ์ง€! Animator Controller์™€ ์—ฐ๋™ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด์ž. ๐ŸŽญ

// ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ปจํŠธ๋กค๋Ÿฌ
public class CharacterAnimationController : MonoBehaviour
{
    private Animator animator;
    private AdvancedCharacterController characterController;
    
    // ์• ๋‹ˆ๋ฉ”์ดํ„ฐ ํŒŒ๋ผ๋ฏธํ„ฐ ์ด๋ฆ„
    private readonly string SPEED_PARAM = "Speed";
    private readonly string IS_JUMPING_PARAM = "IsJumping";
    private readonly string IS_GROUNDED_PARAM = "IsGrounded";
    private readonly string VERTICAL_VELOCITY_PARAM = "VerticalVelocity";
    
    void Start()
    {
        animator = GetComponent<Animator>();
        characterController = GetComponent<AdvancedCharacterController>();
    }
    
    void Update()
    {
        UpdateAnimationParameters();
    }
    
    void UpdateAnimationParameters()
    {
        // ์ด๋™ ์†๋„ ์ „๋‹ฌ
        float speed = characterController.GetCurrentSpeed();
        animator.SetFloat(SPEED_PARAM, speed);
        
        // ์ ํ”„ ์ƒํƒœ ์ „๋‹ฌ
        bool isJumping = characterController.IsJumping();
        animator.SetBool(IS_JUMPING_PARAM, isJumping);
        
        // ์ ‘์ง€ ์ƒํƒœ ์ „๋‹ฌ
        bool isGrounded = !isJumping;
        animator.SetBool(IS_GROUNDED_PARAM, isGrounded);
        
        // ์ˆ˜์ง ์†๋„ ์ „๋‹ฌ (๋‚™ํ•˜ ์• ๋‹ˆ๋ฉ”์ด์…˜์šฉ)
        CharacterController cc = GetComponent<CharacterController>();
        animator.SetFloat(VERTICAL_VELOCITY_PARAM, cc.velocity.y);
    }
    
    // ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ด๋ฒคํŠธ์—์„œ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ๋Š” ๋ฉ”์„œ๋“œ๋“ค
    public void OnFootstep()
    {
        // ๋ฐœ์†Œ๋ฆฌ ์žฌ์ƒ
        AudioSource.PlayClipAtPoint(footstepSound, transform.position);
    }
    
    public void OnLand()
    {
        // ์ฐฉ์ง€ ํšจ๊ณผ
        Debug.Log("Character landed!");
    }
}

๐ŸŽจ Animator Controller ์„ค์ •

Unity์˜ Animator Controller์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํŒŒ๋ผ๋ฏธํ„ฐ๋“ค์„ ๋งŒ๋“ค์–ด์ค˜์•ผ ํ•ด:

๐Ÿ“Š Animator Parameters โ€ข Speed (Float): 0 = Idle, 0~4 = Walk, 4~8 = Run
โ€ข IsJumping (Bool): ์ ํ”„ ์ค‘์ธ์ง€ ์—ฌ๋ถ€
โ€ข IsGrounded (Bool): ๋•…์— ๋‹ฟ์•„์žˆ๋Š”์ง€ ์—ฌ๋ถ€
โ€ข VerticalVelocity (Float): ์ƒ์Šน/ํ•˜๊ฐ• ์†๋„ (๋‚™ํ•˜ ์• ๋‹ˆ๋ฉ”์ด์…˜์šฉ)

๐ŸŽฎ ์ž…๋ ฅ ์‹œ์Šคํ…œ ๊ฐœ์„ ํ•˜๊ธฐ

Unity์˜ ์ƒˆ๋กœ์šด Input System์„ ์‚ฌ์šฉํ•˜๋ฉด ๋” ์œ ์—ฐํ•˜๊ณ  ๊ฐ•๋ ฅํ•œ ์ž…๋ ฅ ์ฒ˜๋ฆฌ๊ฐ€ ๊ฐ€๋Šฅํ•ด. ๊ธฐ์กด Input Manager๋ณด๋‹ค ํ›จ์”ฌ ์ข‹์•„! ๐ŸŽฏ

// New Input System ์‚ฌ์šฉ ์˜ˆ์ œ
using UnityEngine;
using UnityEngine.InputSystem;

public class NewInputCharacterController : MonoBehaviour
{
    private CharacterController controller;
    private Vector2 moveInput;
    private Vector2 lookInput;
    private bool jumpPressed;
    private bool sprintPressed;
    
    [Header("Movement")]
    public float walkSpeed = 4f;
    public float sprintSpeed = 8f;
    public float jumpHeight = 2f;
    public float gravity = -15f;
    
    private Vector3 velocity;
    private bool isGrounded;
    
    void Start()
    {
        controller = GetComponent<CharacterController>();
    }
    
    void Update()
    {
        HandleMovement();
    }
    
    void HandleMovement()
    {
        isGrounded = controller.isGrounded;
        if (isGrounded && velocity.y < 0)
        {
            velocity.y = -2f;
        }
        
        // ์ด๋™ ์†๋„ ๊ฒฐ์ •
        float currentSpeed = sprintPressed ? sprintSpeed : walkSpeed;
        
        // ์ด๋™ ๋ฐฉํ–ฅ ๊ณ„์‚ฐ
        Vector3 move = transform.right * moveInput.x + transform.forward * moveInput.y;
        controller.Move(move * currentSpeed * Time.deltaTime);
        
        // ์ ํ”„
        if (jumpPressed && isGrounded)
        {
            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
            jumpPressed = false;
        }
        
        // ์ค‘๋ ฅ
        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);
    }
    
    // Input System ์ฝœ๋ฐฑ ๋ฉ”์„œ๋“œ๋“ค
    public void OnMove(InputAction.CallbackContext context)
    {
        moveInput = context.ReadValue<Vector2>();
    }
    
    public void OnLook(InputAction.CallbackContext context)
    {
        lookInput = context.ReadValue<Vector2>();
    }
    
    public void OnJump(InputAction.CallbackContext context)
    {
        if (context.performed)
        {
            jumpPressed = true;
        }
    }
    
    public void OnSprint(InputAction.CallbackContext context)
    {
        sprintPressed = context.performed;
    }
}
โš ๏ธ New Input System ์„ค์น˜: Package Manager์—์„œ "Input System"์„ ์„ค์น˜ํ•˜๊ณ , Project Settings์—์„œ Active Input Handling์„ "Both" ๋˜๋Š” "Input System Package (New)"๋กœ ๋ณ€๊ฒฝํ•ด์•ผ ํ•ด!

๐Ÿƒโ€โ™‚๏ธ ๊ณ ๊ธ‰ ์ด๋™ ๊ธฐ๋Šฅ ์ถ”๊ฐ€ํ•˜๊ธฐ

์ด์ œ ๋” ๋ฉ‹์ง„ ๊ธฐ๋Šฅ๋“ค์„ ์ถ”๊ฐ€ํ•ด๋ณด์ž! ๋Œ€์‹œ, ์Šฌ๋ผ์ด๋”ฉ, ๋ฒฝํƒ€๊ธฐ ๊ฐ™์€ ๊ณ ๊ธ‰ ๊ธฐ๋Šฅ๋“ค์ด์•ผ. ๐Ÿš€

๐Ÿ’จ ๋Œ€์‹œ(Dash) ๊ตฌํ˜„

// ๋Œ€์‹œ ๊ธฐ๋Šฅ ์ถ”๊ฐ€
public class DashController : MonoBehaviour
{
    [Header("Dash Settings")]
    public float dashSpeed = 20f;
    public float dashDuration = 0.2f;
    public float dashCooldown = 1f;
    
    private CharacterController controller;
    private bool isDashing = false;
    private float dashTimer = 0f;
    private float cooldownTimer = 0f;
    private Vector3 dashDirection;
    
    void Start()
    {
        controller = GetComponent<CharacterController>();
    }
    
    void Update()
    {
        HandleDash();
        UpdateTimers();
    }
    
    void HandleDash()
    {
        // ๋Œ€์‹œ ์ž…๋ ฅ (์ขŒ์ธก Shift ๋”๋ธ”ํƒญ ๋˜๋Š” ํŠน์ • ํ‚ค)
        if (Input.GetKeyDown(KeyCode.E) && cooldownTimer <= 0f && !isDashing)
        {
            StartDash();
        }
        
        // ๋Œ€์‹œ ์ค‘์ผ ๋•Œ
        if (isDashing)
        {
            controller.Move(dashDirection * dashSpeed * Time.deltaTime);
            
            if (dashTimer <= 0f)
            {
                EndDash();
            }
        }
    }
    
    void StartDash()
    {
        isDashing = true;
        dashTimer = dashDuration;
        cooldownTimer = dashCooldown;
        
        // ํ˜„์žฌ ์ด๋™ ๋ฐฉํ–ฅ์œผ๋กœ ๋Œ€์‹œ
        float horizontal = Input.GetAxis("Horizontal");
        float vertical = Input.GetAxis("Vertical");
        
        if (horizontal == 0f && vertical == 0f)
        {
            // ์ž…๋ ฅ์ด ์—†์œผ๋ฉด ์ „๋ฐฉ์œผ๋กœ ๋Œ€์‹œ
            dashDirection = transform.forward;
        }
        else
        {
            dashDirection = (transform.right * horizontal + transform.forward * vertical).normalized;
        }
        
        // ๋Œ€์‹œ ์ดํŽ™ํŠธ ์žฌ์ƒ
        PlayDashEffect();
    }
    
    void EndDash()
    {
        isDashing = false;
    }
    
    void UpdateTimers()
    {
        if (dashTimer > 0f)
        {
            dashTimer -= Time.deltaTime;
        }
        
        if (cooldownTimer > 0f)
        {
            cooldownTimer -= Time.deltaTime;
        }
    }
    
    void PlayDashEffect()
    {
        // ํŒŒํ‹ฐํด ์ดํŽ™ํŠธ๋‚˜ ์‚ฌ์šด๋“œ ์žฌ์ƒ
        Debug.Log("Dash!");
    }
    
    public bool IsDashing()
    {
        return isDashing;
    }
    
    public float GetDashCooldownPercent()
    {
        return 1f - (cooldownTimer / dashCooldown);
    }
}

๐Ÿง— ๋ฒฝํƒ€๊ธฐ(Wall Running) ๊ตฌํ˜„

// ๋ฒฝํƒ€๊ธฐ ์‹œ์Šคํ…œ
public class WallRunController : MonoBehaviour
{
    [Header("Wall Run Settings")]
    public float wallRunSpeed = 6f;
    public float wallRunDuration = 2f;
    public float wallCheckDistance = 0.7f;
    public float minJumpHeight = 1.5f;
    public LayerMask wallLayer;
    
    private CharacterController controller;
    private bool isWallRunning = false;
    private bool isWallRight = false;
    private bool isWallLeft = false;
    private float wallRunTimer = 0f;
    private RaycastHit wallHit;
    
    void Start()
    {
        controller = GetComponent<CharacterController>();
    }
    
    void Update()
    {
        CheckForWall();
        HandleWallRun();
    }
    
    void CheckForWall()
    {
        // ์˜ค๋ฅธ์ชฝ ๋ฒฝ ์ฒดํฌ
        isWallRight = Physics.Raycast(transform.position, transform.right, out wallHit, 
                                       wallCheckDistance, wallLayer);
        
        // ์™ผ์ชฝ ๋ฒฝ ์ฒดํฌ
        isWallLeft = Physics.Raycast(transform.position, -transform.right, out wallHit, 
                                      wallCheckDistance, wallLayer);
    }
    
    void HandleWallRun()
    {
        bool canWallRun = (isWallRight || isWallLeft) && 
                          !controller.isGrounded && 
                          Input.GetAxis("Vertical") > 0;
        
        if (canWallRun && !isWallRunning)
        {
            StartWallRun();
        }
        else if (isWallRunning)
        {
            ContinueWallRun();
        }
    }
    
    void StartWallRun()
    {
        isWallRunning = true;
        wallRunTimer = wallRunDuration;
        
        Debug.Log("Started wall running!");
    }
    
    void ContinueWallRun()
    {
        wallRunTimer -= Time.deltaTime;
        
        // ์ „์ง„ ์ด๋™
        Vector3 wallNormal = wallHit.normal;
        Vector3 wallForward = Vector3.Cross(wallNormal, Vector3.up);
        
        if ((isWallLeft && Vector3.Dot(wallForward, transform.forward) < 0) ||
            (isWallRight && Vector3.Dot(wallForward, transform.forward) > 0))
        {
            wallForward = -wallForward;
        }
        
        controller.Move(wallForward * wallRunSpeed * Time.deltaTime);
        
        // ์•ฝ๊ฐ„์˜ ์ƒ์Šน๋ ฅ (์ค‘๋ ฅ ์ƒ์‡„)
        controller.Move(Vector3.up * 2f * Time.deltaTime);
        
        // ์นด๋ฉ”๋ผ ๊ธฐ์šธ์ด๊ธฐ ํšจ๊ณผ (์„ ํƒ์‚ฌํ•ญ)
        float tilt = isWallRight ? -15f : 15f;
        Camera.main.transform.localRotation = Quaternion.Euler(0f, 0f, tilt);
        
        // ์ข…๋ฃŒ ์กฐ๊ฑด
        if (wallRunTimer <= 0f || controller.isGrounded || 
            (!isWallRight && !isWallLeft) || Input.GetAxis("Vertical") <= 0)
        {
            EndWallRun();
        }
        
        // ๋ฒฝ์—์„œ ์ ํ”„
        if (Input.GetButtonDown("Jump"))
        {
            WallJump();
        }
    }
    
    void WallJump()
    {
        Vector3 wallNormal = wallHit.normal;
        Vector3 jumpDirection = (wallNormal + Vector3.up).normalized;
        
        // ๋ฒฝ์—์„œ ํŠ•๊ฒจ๋‚˜๊ฐ€๋Š” ์ ํ”„
        controller.Move(jumpDirection * 10f * Time.deltaTime);
        
        EndWallRun();
    }
    
    void EndWallRun()
    {
        isWallRunning = false;
        
        // ์นด๋ฉ”๋ผ ๊ธฐ์šธ๊ธฐ ๋ณต์›
        Camera.main.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
        
        Debug.Log("Ended wall running!");
    }
    
    public bool IsWallRunning()
    {
        return isWallRunning;
    }
}
Advanced Movement Mechanics Dash System ๐Ÿ’จ Quick burst of speed Cooldown system Direction control Speed: 20 units/sec Wall Run System Defies gravity Wall jump capability Slide System Momentum based Lower hitbox Speed boost

๐ŸŽฏ ์ตœ์ ํ™”์™€ ์„ฑ๋Šฅ ๊ฐœ์„ 

์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ๋งŒ๋“ค์—ˆ๋‹ค๋ฉด ์ด์ œ ์ตœ์ ํ™”๋ฅผ ํ•ด์•ผ ํ•ด! ํŠนํžˆ ๋ชจ๋ฐ”์ผ ๊ฒŒ์ž„์ด๋ผ๋ฉด ๋”์šฑ ์ค‘์š”ํ•˜์ง€. ๐Ÿ“ฑ

โšก ์„ฑ๋Šฅ ์ตœ์ ํ™” ์ฒดํฌ๋ฆฌ์ŠคํŠธ

1. Physics ์—…๋ฐ์ดํŠธ ์ฃผ๊ธฐ ์กฐ์ •
Edit โ†’ Project Settings โ†’ Time์—์„œ Fixed Timestep์„ ์กฐ์ •ํ•ด. ๊ธฐ๋ณธ๊ฐ’์€ 0.02(50fps)์ธ๋ฐ, 0.01667(60fps)๋กœ ์˜ฌ๋ฆฌ๋ฉด ๋” ๋ถ€๋“œ๋Ÿฌ์›Œ์ ธ.

2. Raycast ์ตœ์ ํ™”
๋งค ํ”„๋ ˆ์ž„๋งˆ๋‹ค Raycast๋ฅผ ํ•˜์ง€ ๋ง๊ณ , ํ•„์š”ํ•  ๋•Œ๋งŒ ํ•˜๊ฑฐ๋‚˜ ๊ฐ„๊ฒฉ์„ ๋‘๊ณ  ์ฒดํฌํ•ด.

3. Layer Mask ํ™œ์šฉ
Physics ์—ฐ์‚ฐ ์‹œ ๋ถˆํ•„์š”ํ•œ ๋ ˆ์ด์–ด๋Š” ์ œ์™ธํ•ด์„œ ์—ฐ์‚ฐ๋Ÿ‰์„ ์ค„์—ฌ.

4. Object Pooling
๋ฐœ์ž๊ตญ ์ดํŽ™ํŠธ๋‚˜ ๋จผ์ง€ ํŒŒํ‹ฐํด ๊ฐ™์€ ๊ฑด ๋งค๋ฒˆ ์ƒ์„ฑํ•˜์ง€ ๋ง๊ณ  ํ’€๋ง ์‹œ์Šคํ…œ์„ ์‚ฌ์šฉํ•ด.

5. LOD(Level of Detail)
์นด๋ฉ”๋ผ์—์„œ ๋ฉ€๋ฆฌ ์žˆ์„ ๋•Œ๋Š” ๊ฐ„๋‹จํ•œ ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•ด.
// ์ตœ์ ํ™”๋œ Ground Check ์˜ˆ์ œ
public class OptimizedGroundCheck : MonoBehaviour
{
    [Header("Ground Check Settings")]
    public LayerMask groundLayer;
    public float checkRadius = 0.3f;
    public float checkInterval = 0.1f; // 0.1์ดˆ๋งˆ๋‹ค ์ฒดํฌ
    
    private bool isGrounded;
    private float nextCheckTime;
    
    void Update()
    {
        // ์ผ์ • ๊ฐ„๊ฒฉ์œผ๋กœ๋งŒ ์ฒดํฌ
        if (Time.time >= nextCheckTime)
        {
            CheckGround();
            nextCheckTime = Time.time + checkInterval;
        }
    }
    
    void CheckGround()
    {
        // SphereCast๊ฐ€ Raycast๋ณด๋‹ค ๋” ์•ˆ์ •์ 
        isGrounded = Physics.CheckSphere(
            transform.position + Vector3.down * 0.1f,
            checkRadius,
            groundLayer
        );
    }
    
    public bool IsGrounded()
    {
        return isGrounded;
    }
    
    // ๋””๋ฒ„๊ทธ์šฉ ์‹œ๊ฐํ™”
    void OnDrawGizmosSelected()
    {
        Gizmos.color = isGrounded ? Color.green : Color.red;
        Gizmos.DrawWireSphere(transform.position + Vector3.down * 0.1f, checkRadius);
    }
}

๐Ÿ› ๋””๋ฒ„๊น…๊ณผ ๋ฌธ์ œ ํ•ด๊ฒฐ

์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ๋งŒ๋“ค๋‹ค ๋ณด๋ฉด ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ๋ฌธ์ œ์— ๋ถ€๋”ชํžˆ๊ฒŒ ๋ผ. ์ž์ฃผ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ๋“ค๊ณผ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด์ž! ๐Ÿ”ง

โŒ ์ž์ฃผ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ๋“ค ๋ฌธ์ œ 1: ์บ๋ฆญํ„ฐ๊ฐ€ ๊ฒฝ์‚ฌ๋ฉด์—์„œ ๋ฏธ๋„๋Ÿฌ์ ธ์š”!
โ†’ Character Controller์˜ Slope Limit์„ ์กฐ์ •ํ•˜๊ฑฐ๋‚˜, Physics Material์„ ์‚ฌ์šฉํ•ด์„œ ๋งˆ์ฐฐ๋ ฅ์„ ๋†’์—ฌ๋ด.

๋ฌธ์ œ 2: ์ ํ”„๊ฐ€ ๋ถ€์ž์—ฐ์Šค๋Ÿฌ์›Œ์š”!
โ†’ ์ค‘๋ ฅ ๊ฐ’์„ ์กฐ์ •ํ•˜๊ณ , ์ ํ”„ ๋†’์ด ๊ณต์‹์„ ํ™•์ธํ•ด. velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity)

๋ฌธ์ œ 3: ๋ฒฝ์„ ํƒ€๊ณ  ์˜ฌ๋ผ๊ฐ€์š”!
โ†’ Character Controller์˜ Step Offset์„ ์ค„์ด๊ฑฐ๋‚˜, ๋ฒฝ์— Physics Material์„ ์ ์šฉํ•ด.

๋ฌธ์ œ 4: ์นด๋ฉ”๋ผ๊ฐ€ ๋–จ๋ ค์š”!
โ†’ ์นด๋ฉ”๋ผ ์—…๋ฐ์ดํŠธ๋ฅผ LateUpdate()๋กœ ์˜ฎ๊ธฐ๊ณ , Lerp๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋ถ€๋“œ๋Ÿฝ๊ฒŒ ๋งŒ๋“ค์–ด.

๋ฌธ์ œ 5: ๋Œ€๊ฐ์„  ์ด๋™์ด ๋” ๋นจ๋ผ์š”!
โ†’ ์ด๋™ ๋ฒกํ„ฐ๋ฅผ Normalize()ํ•ด์„œ ํฌ๊ธฐ๋ฅผ 1๋กœ ๋งŒ๋“ค์–ด์ค˜.
// ๋””๋ฒ„๊ทธ ์ •๋ณด ํ‘œ์‹œ ์‹œ์Šคํ…œ
public class CharacterDebugInfo : MonoBehaviour
{
    private CharacterController controller;
    private GUIStyle style;
    
    void Start()
    {
        controller = GetComponent<CharacterController>();
        
        // GUI ์Šคํƒ€์ผ ์„ค์ •
        style = new GUIStyle();
        style.fontSize = 16;
        style.normal.textColor = Color.white;
    }
    
    void OnGUI()
    {
        if (!Debug.isDebugBuild) return;
        
        int y = 10;
        int lineHeight = 25;
        
        GUI.Label(new Rect(10, y, 300, 20), $"Position: {transform.position}", style);
        y += lineHeight;
        
        GUI.Label(new Rect(10, y, 300, 20), $"Velocity: {controller.velocity}", style);
        y += lineHeight;
        
        GUI.Label(new Rect(10, y, 300, 20), $"Is Grounded: {controller.isGrounded}", style);
        y += lineHeight;
        
        GUI.Label(new Rect(10, y, 300, 20), $"Speed: {controller.velocity.magnitude:F2}", style);
        y += lineHeight;
        
        // ์ž…๋ ฅ ์ •๋ณด
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
        GUI.Label(new Rect(10, y, 300, 20), $"Input: ({h:F2}, {v:F2})", style);
    }
    
    // Scene ๋ทฐ์— ์‹œ๊ฐ์  ๋””๋ฒ„๊ทธ ์ •๋ณด
    void OnDrawGizmos()
    {
        if (controller == null) return;
        
        // ์†๋„ ๋ฒกํ„ฐ ํ‘œ์‹œ
        Gizmos.color = Color.blue;
        Gizmos.DrawLine(transform.position, transform.position + controller.velocity);
        
        // ์ด๋™ ๋ฐฉํ–ฅ ํ‘œ์‹œ
        Gizmos.color = Color.green;
        Gizmos.DrawLine(transform.position, transform.position + transform.forward * 2f);
    }
}

๐ŸŽฎ ์‹ค์ „ ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ

์‹ค์ œ ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ์ฝ”๋“œ๋ฅผ ๋ชจ๋“ˆํ™”ํ•ด์„œ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒŒ ์ค‘์š”ํ•ด. ๊น”๋”ํ•œ ๊ตฌ์กฐ๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž! ๐Ÿ“

๐Ÿ“‚ ๊ถŒ์žฅ ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ


Scripts/

โ”œโ”€โ”€ Character/

โ”‚   โ”œโ”€โ”€ Movement/

โ”‚   โ”‚   โ”œโ”€โ”€ CharacterController.cs

โ”‚   โ”‚   โ”œโ”€โ”€ MovementState.cs

โ”‚   โ”‚   โ””โ”€โ”€ MovementConfig.cs

โ”‚   โ”œโ”€โ”€ Animation/

โ”‚   โ”‚   โ”œโ”€โ”€ CharacterAnimator.cs

โ”‚   โ”‚   โ””โ”€โ”€ AnimationConfig.cs

โ”‚   โ”œโ”€โ”€ Input/

โ”‚   โ”‚   โ”œโ”€โ”€ InputHandler.cs

โ”‚   โ”‚   โ””โ”€โ”€ InputActions.inputactions

โ”‚   โ””โ”€โ”€ Camera/

โ”‚       โ”œโ”€โ”€ ThirdPersonCamera.cs

โ”‚       โ””โ”€โ”€ CameraConfig.cs

โ”œโ”€โ”€ Utilities/

โ”‚   โ”œโ”€โ”€ GroundChecker.cs

โ”‚   โ””โ”€โ”€ PhysicsHelper.cs

โ””โ”€โ”€ Debug/

โ””โ”€โ”€ CharacterDebugger.cs
// ScriptableObject๋ฅผ ์‚ฌ์šฉํ•œ ์„ค์ • ๊ด€๋ฆฌ
[CreateAssetMenu(fileName = "MovementConfig", menuName = "Character/Movement Config")]
public class MovementConfig : ScriptableObject
{
    [Header("Speed Settings")]
    public float walkSpeed = 4f;
    public float sprintSpeed = 8f;
    public float crouchSpeed = 2f;
    
    [Header("Jump Settings")]
    public float jumpHeight = 2.5f;
    public float gravity = -15f;
    public float coyoteTime = 0.2f; // ๋•…์—์„œ ๋–จ์–ด์ง„ ํ›„ ์ ํ”„ ๊ฐ€๋Šฅ ์‹œ๊ฐ„
    public float jumpBufferTime = 0.2f; // ์ ํ”„ ์ž…๋ ฅ ๋ฒ„ํผ ์‹œ๊ฐ„
    
    [Header("Air Control")]
    public float airControlPercent = 0.5f;
    public float airDrag = 0.1f;
    
    [Header("Ground Check")]
    public float groundCheckDistance = 0.4f;
    public LayerMask groundLayer;
    
    [Header("Slope Handling")]
    public float maxSlopeAngle = 45f;
    public float slopeForce = 8f;
}

// ์‚ฌ์šฉ ์˜ˆ์ œ
public class ModularCharacterController : MonoBehaviour
{
    public MovementConfig config;
    private CharacterController controller;
    
    void Start()
    {
        controller = GetComponent<CharacterController>();
    }
    
    void Update()
    {
        // config์˜ ๊ฐ’๋“ค์„ ์‚ฌ์šฉ
        float speed = Input.GetKey(KeyCode.LeftShift) ? 
                      config.sprintSpeed : config.walkSpeed;
        // ... ๋‚˜๋จธ์ง€ ๋กœ์ง
    }
}
๐Ÿ’ก ScriptableObject์˜ ์žฅ์ : ์„ค์ • ๊ฐ’๋“ค์„ ์—์…‹์œผ๋กœ ๊ด€๋ฆฌํ•˜๋ฉด ์—ฌ๋Ÿฌ ์บ๋ฆญํ„ฐ๊ฐ€ ๊ฐ™์€ ์„ค์ •์„ ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๊ณ , ์ฝ”๋“œ ์ˆ˜์ • ์—†์ด Inspector์—์„œ ๋ฐ”๋กœ ์กฐ์ •ํ•  ์ˆ˜ ์žˆ์–ด!

๐ŸŽจ ๋ชจ๋ฐ”์ผ ์ตœ์ ํ™”์™€ ํ„ฐ์น˜ ์ปจํŠธ๋กค

๋ชจ๋ฐ”์ผ ๊ฒŒ์ž„์„ ๋งŒ๋“ ๋‹ค๋ฉด ํ„ฐ์น˜ ์ž…๋ ฅ๊ณผ ์„ฑ๋Šฅ ์ตœ์ ํ™”๊ฐ€ ํ•„์ˆ˜์•ผ! ๐Ÿ“ฑ ๊ฐ€์ƒ ์กฐ์ด์Šคํ‹ฑ์„ ๊ตฌํ˜„ํ•ด๋ณด์ž.

// ๋ชจ๋ฐ”์ผ์šฉ ๊ฐ€์ƒ ์กฐ์ด์Šคํ‹ฑ
public class VirtualJoystick : MonoBehaviour
{
    [Header("Joystick Settings")]
    public RectTransform joystickBackground;
    public RectTransform joystickHandle;
    public float handleRange = 50f;
    public float deadZone = 0.1f;
    
    private Vector2 input = Vector2.zero;
    private int touchId = -1;
    
    void Update()
    {
        HandleTouch();
    }
    
    void HandleTouch()
    {
        // ํ„ฐ์น˜ ์ž…๋ ฅ ์ฒ˜๋ฆฌ
        if (Input.touchCount > 0)
        {
            for (int i = 0; i < Input.touchCount; i++)
            {
                Touch touch = Input.GetTouch(i);
                
                // ์ƒˆ๋กœ์šด ํ„ฐ์น˜ ์‹œ์ž‘
                if (touch.phase == TouchPhase.Began && touchId == -1)
                {
                    // ์กฐ์ด์Šคํ‹ฑ ์˜์—ญ ๋‚ด์˜ ํ„ฐ์น˜์ธ์ง€ ํ™•์ธ
                    if (RectTransformUtility.RectangleContainsScreenPoint(
                        joystickBackground, touch.position))
                    {
                        touchId = touch.fingerId;
                        UpdateJoystick(touch.position);
                    }
                }
                // ํ„ฐ์น˜ ์ด๋™
                else if (touch.fingerId == touchId)
                {
                    if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary)
                    {
                        UpdateJoystick(touch.position);
                    }
                    // ํ„ฐ์น˜ ์ข…๋ฃŒ
                    else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
                    {
                        ResetJoystick();
                    }
                }
            }
        }
        else
        {
            ResetJoystick();
        }
    }
    
    void UpdateJoystick(Vector2 touchPosition)
    {
        Vector2 localPoint;
        RectTransformUtility.ScreenPointToLocalPointInRectangle(
            joystickBackground, touchPosition, null, out localPoint);
        
        // ์ž…๋ ฅ ๊ฐ’ ๊ณ„์‚ฐ
        Vector2 direction = localPoint / handleRange;
        input = direction.magnitude > 1f ? direction.normalized : direction;
        
        // ๋ฐ๋“œ์กด ์ ์šฉ
        if (input.magnitude < deadZone)
        {
            input = Vector2.zero;
        }
        
        // ํ•ธ๋“ค ์œ„์น˜ ์—…๋ฐ์ดํŠธ
        joystickHandle.anchoredPosition = input * handleRange;
    }
    
    void ResetJoystick()
    {
        touchId = -1;
        input = Vector2.zero;
        joystickHandle.anchoredPosition = Vector2.zero;
    }
    
    public Vector2 GetInput()
    {
        return input;
    }
}

// ๋ชจ๋ฐ”์ผ ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ
public class MobileCharacterController : MonoBehaviour
{
    public VirtualJoystick joystick;
    private CharacterController controller;
    public float moveSpeed = 5f;
    
    void Start()
    {
        controller = GetComponent<CharacterController>();
    }
    
    void Update()
    {
        Vector2 input = joystick.GetInput();
        
        // ์นด๋ฉ”๋ผ ๊ธฐ์ค€ ์ด๋™
        Vector3 cameraForward = Camera.main.transform.forward;
        Vector3 cameraRight = Camera.main.transform.right;
        cameraForward.y = 0f;
        cameraRight.y = 0f;
        cameraForward.Normalize();
        cameraRight.Normalize();
        
        Vector3 move = cameraForward * input.y + cameraRight * input.x;
        controller.Move(move * moveSpeed * Time.deltaTime);
        
        // ์บ๋ฆญํ„ฐ ํšŒ์ „
        if (move.magnitude > 0.1f)
        {
            Quaternion targetRotation = Quaternion.LookRotation(move);
            transform.rotation = Quaternion.Slerp(
                transform.rotation, targetRotation, Time.deltaTime * 10f);
        }
    }
}

๐ŸŒŸ ์žฌ๋Šฅ๋„ท์—์„œ ๋” ๋ฐฐ์šฐ๊ธฐ

์—ฌ๊ธฐ๊นŒ์ง€ Unity 3D ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค์˜ ๊ธฐ์ดˆ๋ถ€ํ„ฐ ๊ณ ๊ธ‰ ๊ธฐ๋Šฅ๊นŒ์ง€ ๋ชจ๋‘ ์‚ดํŽด๋ดค์–ด! ๐ŸŽ‰ ํ•˜์ง€๋งŒ ์‹ค์ œ๋กœ ๊ฒŒ์ž„์„ ๋งŒ๋“ค๋‹ค ๋ณด๋ฉด ๋” ๋ณต์žกํ•œ ์ƒํ™ฉ๋“ค์„ ๋งˆ์ฃผํ•˜๊ฒŒ ๋  ๊ฑฐ์•ผ. ๊ทธ๋Ÿด ๋•Œ๋Š” ์žฌ๋Šฅ๋„ท์—์„œ ์ „๋ฌธ๊ฐ€๋“ค์˜ ๋„์›€์„ ๋ฐ›์•„๋ณด๋Š” ๊ฒƒ๋„ ์ข‹์€ ๋ฐฉ๋ฒ•์ด์•ผ!

๐ŸŽ“ ์žฌ๋Šฅ๋„ท ํ™œ์šฉ ํŒ โ€ข 1:1 ์ฝ”๋“œ ๋ฆฌ๋ทฐ: ๋‚ด๊ฐ€ ์ž‘์„ฑํ•œ ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ ์ฝ”๋“œ๋ฅผ ์ „๋ฌธ๊ฐ€์—๊ฒŒ ๊ฒ€ํ† ๋ฐ›์„ ์ˆ˜ ์žˆ์–ด
โ€ข ๋งž์ถคํ˜• ํŠœํ† ๋ฆฌ์–ผ: ๋‚ด ํ”„๋กœ์ ํŠธ์— ๋”ฑ ๋งž๋Š” ๊ธฐ๋Šฅ ๊ตฌํ˜„ ๋ฐฉ๋ฒ•์„ ๋ฐฐ์šธ ์ˆ˜ ์žˆ์ง€
โ€ข ์ตœ์ ํ™” ์ปจ์„คํŒ…: ๊ฒŒ์ž„ ์„ฑ๋Šฅ์„ ๊ฐœ์„ ํ•˜๋Š” ์ „๋ฌธ์ ์ธ ์กฐ์–ธ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ์–ด
โ€ข ๋ฒ„๊ทธ ํ•ด๊ฒฐ: ํ•ด๊ฒฐํ•˜๊ธฐ ์–ด๋ ค์šด ๋ฒ„๊ทธ๋ฅผ ํ•จ๊ป˜ ์ฐพ์•„๋‚ผ ์ˆ˜ ์žˆ์–ด

๐ŸŽฏ ๋งˆ๋ฌด๋ฆฌํ•˜๋ฉฐ

์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค์€ ๊ฒŒ์ž„ ๊ฐœ๋ฐœ์˜ ํ•ต์‹ฌ์ด์•ผ. ์ฒ˜์Œ์—๋Š” ์–ด๋ ต๊ฒŒ ๋А๊ปด์งˆ ์ˆ˜ ์žˆ์ง€๋งŒ, ํ•˜๋‚˜์”ฉ ๊ตฌํ˜„ํ•ด๋ณด๋ฉด์„œ ์ตํžˆ๋‹ค ๋ณด๋ฉด ์–ด๋А์ƒˆ ์ž์œ ์ž์žฌ๋กœ ๋‹ค๋ฃฐ ์ˆ˜ ์žˆ๊ฒŒ ๋  ๊ฑฐ์•ผ! ๐Ÿ’ช

๐Ÿ“š ํ•ต์‹ฌ ์š”์•ฝ

1. ๊ธฐ๋ณธ ์ด๋™: Character Controller๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ฐ€์žฅ ์•ˆ์ •์ ์ด์•ผ
2. ๋ฌผ๋ฆฌ ์ฒ˜๋ฆฌ: Rigidbody๋Š” ๋ณต์žกํ•œ ๋ฌผ๋ฆฌ ์ƒํ˜ธ์ž‘์šฉ์ด ํ•„์š”ํ•  ๋•Œ ์‚ฌ์šฉํ•ด
3. ์นด๋ฉ”๋ผ: LateUpdate()์—์„œ ์ฒ˜๋ฆฌํ•˜๊ณ  Lerp๋กœ ๋ถ€๋“œ๋Ÿฝ๊ฒŒ ๋งŒ๋“ค์–ด
4. ์• ๋‹ˆ๋ฉ”์ด์…˜: Animator Parameters๋กœ ์ƒํƒœ๋ฅผ ์ „๋‹ฌํ•ด
5. ์ตœ์ ํ™”: ๋ถˆํ•„์š”ํ•œ ์—ฐ์‚ฐ์„ ์ค„์ด๊ณ  Object Pooling์„ ํ™œ์šฉํ•ด
6. ๋””๋ฒ„๊น…: Gizmos์™€ GUI๋ฅผ ํ™œ์šฉํ•ด์„œ ์‹œ๊ฐ์ ์œผ๋กœ ํ™•์ธํ•ด
7. ๋ชจ๋“ˆํ™”: ScriptableObject๋กœ ์„ค์ •์„ ๊ด€๋ฆฌํ•˜๋ฉด ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ์‰ฌ์›Œ์ ธ

์ด์ œ ๋„ˆ๋งŒ์˜ ๋ฉ‹์ง„ ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ๋งŒ๋“ค์–ด๋ด! ๐ŸŽฎ ๋ง‰ํžˆ๋Š” ๋ถ€๋ถ„์ด ์žˆ๋‹ค๋ฉด ์žฌ๋Šฅ๋„ท์˜ '์ง€์‹์ธ์˜ ์ˆฒ'์—์„œ ๋‹ค๋ฅธ ๊ฐœ๋ฐœ์ž๋“ค์˜ ๊ฒฝํ—˜๋‹ด๋„ ์ฐพ์•„๋ณด๊ณ , ํ•„์š”ํ•˜๋‹ค๋ฉด ์ „๋ฌธ๊ฐ€์˜ ๋„์›€๋„ ๋ฐ›์•„๋ณด์ž. ๊ฒŒ์ž„ ๊ฐœ๋ฐœ์€ ํ˜ผ์ž ํ•˜๋Š” ๊ฒŒ ์•„๋‹ˆ๋ผ ํ•จ๊ป˜ ์„ฑ์žฅํ•˜๋Š” ๊ฑฐ๋‹ˆ๊นŒ! ๐ŸŒฑ

ํ–‰๋ณตํ•œ ์ฝ”๋”ฉ ๋˜๊ธธ ๋ฐ”๋ผ! Happy coding! ๐Ÿš€โœจ

๋Œ“๊ธ€ ์ž‘์„ฑ

์ด ๊ธ€์— ๋Œ€ํ•œ ์—ฌ๋Ÿฌ๋ถ„์˜ ์ƒ๊ฐ์„ ๋“ค๋ ค์ฃผ์„ธ์š”

๋Œ“๊ธ€ 0
๋Œ“๊ธ€์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘์ž…๋‹ˆ๋‹ค.

์•„์ง ๋Œ“๊ธ€์ด ์—†์Šต๋‹ˆ๋‹ค.