Programming/Dev

[010] 플레이어 컨트롤2

LaivY 2023. 7. 29. 21:07

DevLog

[009] 플레이어 컨트롤에서 작업했던 코드들을 좀 더 다듬고,

플렛폼 관련 버그를 수정했다.

 

 

 

 

void Player::InputComponent::Update(FLOAT deltaTime)
{
    // 좌우 이동
    int dir{ 0 };
    if (GetAsyncKeyState(VK_LEFT) & 0x8000)
        --dir;
    if (GetAsyncKeyState(VK_RIGHT) & 0x8000)
        ++dir;
    m_player->SetDirection(static_cast<Direction>(dir));

    // 점프
    if (GetAsyncKeyState('C') & 0x8000 && m_player->m_physicsComponent.CanJump())
    {
        m_player->OnJump();
    }
}

이전에는 InputComponent::Update 함수에서 직접 다른 컴포넌트에 접근하여 함수를 호출했었다.

한 컴포넌트에서 다른 컴포넌트로 직접 접근하는건 최대한 줄이는 방향으로 수정했다.

 

 

 

 

void Player::PhysicsComponent::Update(FLOAT deltaTime)
{
    ...
    // 움직이기 이전, 이후 플레이어 y좌표 사이에 이전 플렛폼 높이가 있다면 착지한 것
    FLOAT platformHeight{ -FLT_MAX };
    if (beforePlatform)
        platformHeight = beforePlatform->GetHeight(afterPosition.x);
    if (!m_isOnPlatform && afterPosition.y <= platformHeight)
    {
        afterPlatform = beforePlatform;
        m_platform = afterPlatform;
        m_player->OnLanding();
    }
    else
    {
        m_platform = afterPlatform;
    }
    ...
}

플렛폼 착지 판정 조건문을 변경했다.

기존에는 움직인 전, 후의 y좌표 사이에 플렛폼이 위치해있으면 착지했다고 판정했는데,

그렇게 할 경우 플렛폼이 대각선으로 되어있을 때 착지하지 못하는 경우가 있었다.

 

컴포넌트 관련 코드들은 앞으로 갈 길이 먼 것 같다.

어떤 구조로 구성하는게 좋은건지 계속해서 고민해야할 것 같다.

 

 

 

 

플렛폼 착지

그리고 디버깅을 위해 플렛폼 판정이 있는 부분을 선으로 그리도록 했다.

플렛폼 기능을 잘 하는 것 같다!