이게... 내가 짠 코드는 아니고 GPT쨩이 짜준 코드란 말이야?


전부 다 GPT가 해준 건 아니고 벽 이동 관련 부분만 어려워서 GPT한테 맡김


근데 조금 버그가 나서...


내가 어렵다고 GPT한테 맡긴 걸 내가 고칠 수 있을리는 전무하고 해서 님들에게 헬프콜 넣어봄.


내가 만들고자 하는 건 지금 벽점프임.


나중에는 조금 더 어려운 것도 만들겠지만, 지금은 이동의 기초면 충분해.


그래서... 이렇게 대충 벽점프를 해달라고 GPT한테 해줬는데





봤음? 벽점프가 끝나니까 캐릭터가 어디 막힌 것 처럼 딱딱하게 굳어버렸음.


그걸 고치고 싶음 나는.


코드 전체 짜달라는 건 제지 대상이라니까 딱 어느 부분에서 버그가 났는지 힌트만 줘도 됨.



아래는 코드 전문임


그... 잘부탁드립니다.


using System.Collections;

using UnityEngine;


public class Hero_move : MonoBehaviour

{

    public float moveSpeed = 5f; // 이동 속도

    public float jumpForce = 10f; // 점프 힘

    public float wallJumpForce = 10f; // 벽 점프 힘

    public float wallSlideSpeed = 1f; // 벽 슬라이딩 속도

    public float wallJumpDisableTime = 0.3f; // 벽 점프 후 이동 방향 전환을 못하는 시간


    private Rigidbody2D rb;

    private bool isGrounded;

    private bool isTouchingWall;

    private bool isWallSliding;

    private bool wallJumpDisabled;

    private float disableTimer;


    void Start()

    {

        rb = GetComponent<Rigidbody2D>();

    }


    void Update()

    {

        // 좌우 이동

        float horizontalInput = Input.GetAxis("Horizontal");

        Vector2 moveDirection = new Vector2(horizontalInput, 0f);


        // 벽 점프 후 일정 시간 동안 이동 방향 전환을 못하도록 함

        if (wallJumpDisabled)

        {

            disableTimer -= Time.deltaTime;

            if (disableTimer <= 0f)

            {

                wallJumpDisabled = false;

            }

        }


        // 벽 슬라이딩

        if (isTouchingWall && !isGrounded && rb.velocity.y < 0)

        {

            isWallSliding = true;

            rb.velocity = new Vector2(rb.velocity.x, -wallSlideSpeed);

        }

        else

        {

            isWallSliding = false;

        }


        // 벽 점프

        if (Input.GetKeyDown(KeyCode.Space))

        {

            if (isGrounded)

            {

                rb.velocity = new Vector2(rb.velocity.x, jumpForce);

            }

            else if (isTouchingWall && !isGrounded)

            {

                // 벽에 붙어있을 때 벽 반대쪽 대각선으로 점프

                float wallJumpDirection = isTouchingWall ? -Mathf.Sign(moveDirection.x) : 0f;

                rb.velocity = new Vector2(wallJumpDirection * wallJumpForce, jumpForce);

                wallJumpDisabled = true;

                disableTimer = wallJumpDisableTime;

            }

        }


        // 플레이어 이동

        if (!isWallSliding && !wallJumpDisabled) // 벽에 붙은 상태에서는 좌우 이동이 안되도록 함

        {

            rb.velocity = new Vector2(moveDirection.x * moveSpeed, rb.velocity.y);

        }

    }


    void OnCollisionEnter2D(Collision2D collision)

    {

        // 바닥과 벽 접촉 여부 체크

        if (collision.gameObject.CompareTag("Ground"))

        {

            isGrounded = true;

        }

        else if (collision.gameObject.CompareTag("Wall"))

        {

            isTouchingWall = true;

        }

    }


    void OnCollisionExit2D(Collision2D collision)

    {

        // 바닥과 벽 접촉 여부 체크 해제

        if (collision.gameObject.CompareTag("Ground"))

        {

            isGrounded = false;

        }

        else if (collision.gameObject.CompareTag("Wall"))

        {

            isTouchingWall = false;

        }

    }

}