본문 바로가기

내일배움캠프/[P7-Team.] CastAway

[TIL 24.06.05] Raycast Trouble Shooting

.

목   차

     


     

    RayCastHit을 받는데 카메라에서 쏘는 레이가 3인칭인 캐릭터에 가려져서 중간에끊기는 문제가 발생했다.

     

    RaycastHit을 연속적으로 받는 것으로 해결했다. 

    RaycastHit[] hits = Physics.RaycastAll(ray, maxCheckDistance, layerMask);
    bool interactableFound = false;
    
    foreach (RaycastHit hit in hits)
    {
        //Player 레이어 무시.
        if (((1 << hit.collider.gameObject.layer) & layerMask) != 0)
        {
            if (hit.collider.gameObject != curInteractGameObject)
            {
                curInteractGameObject = hit.collider.gameObject;
    
                if (hit.collider.gameObject.TryGetComponent(out IInteractable interactable))
                {
                    curInteractable = interactable;
                    curInteractable.GetInteractPrompt();
                }
            }
            interactableFound = true;
            break; // 첫 번째 충돌체만 처리하고 루프 종료.
        }
    }
    
    if (!interactableFound)
    {
        curInteractGameObject = null; // 부딪히지 않았다면 초기화
        curInteractable = null;
    }

     

     

     

    '내일배움캠프 > [P7-Team.] CastAway' 카테고리의 다른 글

    [TIL 24.06.03] 스크롤 바  (0) 2024.06.03