# Portal

참고 영상

<https://youtu.be/cuQao3hEKfs?si=LGnK3tyzF9ThQDRi>

<https://www.youtube.com/watch?v=cWpFZbjtSQg>

<figure><img src="/files/PQwqYg15yEKh3fMNtWJB" alt=""><figcaption></figcaption></figure>

* 포탈 안 타지는 문제 : character controller 켜져있으면 순간이동을 씹음
* 방향 판정 문제 : 영상대로 plane을 쓴게 아니라 quad로 써서 그랬음
* 무한 이동 문제 : collider가 아니라 부모 portal 오브젝트를 teleport receiver로 사용해서 그랬던거
* 포탈 탈 때 약간 덜컹거림 : 포탈의 월드 높이를 동일하게 맞추지 않음
* 렌더가 이상하고 텔레포트 위치도 이상해서 계속 포탈 타짐 : 포탈을 부모 오브젝트로 두지 않고 렌더 텍스쳐 오브젝트와 한 묶음으로 만들어놓음
* 부모 포탈을 만들었는데도 시야가 이상함 : 렌더 텍스쳐를 여전히 포탈처럼 할당하고 있었음

```cs
// Sets the thickness of the portal screen so as not to clip with camera near plane when player goes through
void ProtectScreenFromClipping() {
    float halfHeight = playerCam.nearClipPlane * Mathf.Tan(playerCam.fieldOfView * 0.5f * Mathf.Deg2Rad);
    float halfWidth  = halfHeight * playerCam.aspect;
    float dstToNearClipPlaneCorner = new Vector3(halfWidth, halfHeight, playerCam.nearClipPlane).magnitude;

    Transform screenT = screen.transform;
    bool camFacingSameDirAsPortal = Vector3.Dot(transform.forward,
                                                transform.position - playerCam.transform.position) > 0;
    screenT.localScale    = new Vector3(screenT.localScale.x,
                                        screenT.localScale.y,
                                        dstToNearClipPlaneCorner);
    screenT.localPosition = Vector3.forward * dstToNearClipPlaneCorner *
                            (camFacingSameDirAsPortal ? 0.5f : -0.5f);
}
```

* fieldOfView (FOV) : 세로로 얼마나 보이는지 결정하는 각도
* nearClipPlane : 카메라에서 near clip plane까지의 거리
* `halfHeight` : near clip plane의 세로 반절 높이
* 카메라.aspect : 스크린 너비를 높이로 나눈 값
* `dstToNearClipPlaneCorner` : 카메라에서 스크린 모서리까지의 거리
* `screenT.localScale = ...` : 포탈 스크린(큐브)의 z축 크기를 `dstToNearClipPlaneCorner` 만큼 늘린다
* `screenT.localPosition = ...` : 큐브를 늘려놨으면 그것의 반절만큼 포탈의 방향 기준 뒤로 빠진다. 플레이어에게는 평면으로 보이도록.

즉, 절두체 피라미드의 잘려진 앞부분만큼 크기를 늘려준다는 의미.\
이렇게 하면 코를 박아도 절단면이 보이지 않는다.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lazyartisan.gitbook.io/note/main-page/r-and-d/portal.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
