> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/creator/content-creator-ko/sdk7/interactivity/button-events/proximity-events.md). Agents can also search and read this documentation through its [MCP server](https://docs.decentraland.org/~gitbook/mcp).

# 근접 이벤트

플레이어가 엔티티의 근접 범위에 들어오거나 벗어날 때를 감지합니다.

근접 상호작용을 사용하면 플레이어가 엔티티 가까이에 있고 대략 엔티티를 향하고 있을 때, 커서로 엔티티를 가리키지 않아도 엔티티가 버튼 이벤트에 반응할 수 있습니다.

기존 포인터 이벤트는 레이 캐스팅을 사용합니다. 이벤트를 트리거하는 버튼을 누르려면 먼저 플레이어가 커서로 엔티티의 콜라이더를 가리켜야 합니다. 반면 근접 이벤트는 플레이어의 커서가 향하는 방향과 관계없이 아바타 주변의 지정된 영역 안에 있는 엔티티를 확인합니다.

근접 상호작용에서 고려하는 상호작용 영역은 플레이어의 위치에서 앞쪽으로 뻗어 나가는 넓은 구형 부채꼴 영역입니다. 포인터 이벤트와 달리 카메라가 향하는 방향과 별개로 아바타가 향하는 방향이 중요합니다.

더 구체적인 사용자 지정 로직을 설정하려면 원시 데이터를 직접 처리하고 [고급](https://docs.decentraland.org/creator/content-creator-ko/sdk7/interactivity/button-events/advanced-button-events.md) 접근 방식을 사용할 수 있습니다.

엔티티가 상호작용 가능하려면 [콜라이더](https://docs.decentraland.org/creator/content-creator-ko/sdk7/3d/colliders.md)가 있어야 합니다. 자세한 내용은 [장애물](https://docs.decentraland.org/creator/content-creator-ko/sdk7/interactivity/button-events/click-events.md#obstacles) 을 참조하세요.

## 근접 콜백 등록

다음 `pointerEventsSystem` 근접 이벤트를 위한 도우미 함수를 포함하며, 다음과 같은 패턴을 따릅니다. [포인터 이벤트 콜백](https://docs.decentraland.org/creator/content-creator-ko/sdk7/interactivity/button-events/register-callback.md).

### 근접 버튼 누르기

사용하세요 `pointerEventsSystem.onProximityDown` 플레이어가 범위 내에 있을 때 버튼 누름을 감지하려면 사용하세요. 다음과 달리 `onPointerDown`, 플레이어가 커서를 엔터티에 맞출 필요가 없습니다.

```ts
pointerEventsSystem.onProximityDown(
    {
        entity: myEntity,
        opts: {
            button: InputAction.IA_PRIMARY,
            hoverText: 'Press E',
            maxDistance: 5,
        },
    },
    function () {
        console.log('Player pressed button near entity')
    }
)
```

사용하세요 `pointerEventsSystem.onProximityUp` 플레이어가 범위 내에서 버튼을 놓는 시점을 감지할 수 있습니다.

```ts
pointerEventsSystem.onProximityUp(
    {
        entity: myEntity,
        opts: {
            button: InputAction.IA_PRIMARY,
            hoverText: 'Release E',
            maxDistance: 5,
        },
    },
    function () {
        console.log('Player released button near entity')
    }
)
```

{% hint style="warning" %}
**📔 참고**: 하나의 `onProximityDown` 그리고 하나의 `onProximityUp` 엔티티별로 등록할 수 있습니다. 추가한 후에는 제거할 때까지 계속 수신 대기합니다. 동작을 계속 다시 설정하게 되므로 시스템 루프 안에서 호출하지 마세요.
{% endhint %}

## 근접 이벤트 유형

다음에 새로운 값 두 개가 추가되었습니다. `PointerEventType` 열거형입니다.

* `PET_PROXIMITY_ENTER`: 플레이어가 엔티티의 근접 범위 안으로 들어오면 트리거됩니다.
* `PET_PROXIMITY_LEAVE`: 플레이어가 엔티티의 근접 범위를 벗어나면 트리거됩니다.

다음은 ...와 함께 사용할 수 있습니다 `PointerEvents`  컴포넌트와 `inputSystem` 을 사용해 [시스템 기반 접근 방식](https://docs.decentraland.org/creator/content-creator-ko/sdk7/interactivity/button-events/system-based-events.md#proximity-events)을 적용할 수 있습니다. 이 접근 방식은 다음 필드를 사용해 근접 버튼 누름도 지원합니다:  `InteractionType.PROXIMITY`  필드입니다.

## 우선순위

범위 안에 여러 엔티티가 있고 같은 입력에 반응할 수 있는 경우, 기본적으로 가장 가까운 엔티티 하나만 활성화됩니다. 어떤 엔티티가 우선할지 제어하려면  `priority` 필드를 사용하세요. 우선순위 값이  **더 높은** 엔티티가 먼저 반응합니다.

플레이어가 근접 상호작용이 있는 엔티티의 범위 안에 있으면서 커서로 포인터 상호작용이 있는 엔티티를 가리키는 경우, 포인터 상호작용이 있는 엔티티가 항상 우선합니다. 이때도 활성화되는 엔티티는 하나뿐입니다.

```ts
pointerEventsSystem.onProximityDown(
    {
        entity: doorEntity,
        opts: {
            button: InputAction.IA_PRIMARY,
            hoverText: 'Open door',
            maxDistance: 5,
            priority: 2,
        },
    },
    function () {
        console.log('Door activated')
    }
)

pointerEventsSystem.onProximityDown(
    {
        entity: floorEntity,
        opts: {
            button: InputAction.IA_PRIMARY,
            hoverText: 'Step here',
            maxDistance: 5,
            priority: 1,
        },
    },
    function () {
        console.log('Floor activated')
    }
)
```

위 예시에서 두 엔티티가 모두 범위 안에 있으면 우선순위가 더 높은 문 엔티티가 반응합니다.

또한  `priority`  필드는  `PointerEvents`  컴포넌트의 속성에서도 설정할 수 있습니다.

## 옵션

근접 헬퍼 함수는 포인터 헬퍼 함수와 동일한 옵션을 사용합니다.

* `button`: 수신할 버튼입니다. 지원되는 옵션은  [포인터 버튼](https://docs.decentraland.org/creator/content-creator-ko/sdk7/interactivity/button-events/click-events.md#pointer-buttons) 을 참조하세요.
* `maxDistance`: 플레이어의  **아바타** 에서 엔티티까지의 최대 거리(미터)입니다. 기본값은 10입니다.
* `hoverText`: 플레이어가 엔티티 근처에 있을 때 UI에 표시할 텍스트입니다.
* `showHighlight`: true이면 플레이어가 범위 안에 있을 때 엔티티의 가장자리를 강조 표시합니다. 기본값은  *true* 입니다.
* `showFeedback`: true이면 엔티티 중심 주변에 마우스를 올렸을 때의 피드백을 표시합니다. 기본값은  *true* 입니다.
* `priority`: 여러 엔티티가 근접해 있을 때 우선순위를 결정합니다. 값이 높을수록 우선합니다. 우선순위 값이 같은 엔티티가 여러 개라면 가장 가까운 엔티티가 선택됩니다.

`maxPlayerDistance` 는 더 이상 사용되지 않는 별칭이며,  `maxDistance`와 같습니다. 두 값 모두 아바타로부터의 거리를 측정하므로 새 장면에서는  `maxDistance` 을 사용하세요.

### 범위 안에 있는 것으로 간주되는 조건

근접 이벤트는  **플레이어 캡슐의 중심**에서 엔티티 콜라이더의 가장 가까운 지점까지의 거리를 측정합니다. 이 지점은 커서 클릭이 기준으로 삼는 위치보다 대략 1미터 높기 때문에, 같은 위치도 각 경로에서 측정하면 거리가 약간 다르게 나올 수 있습니다.

거리만으로는 충분하지 않습니다. 근접 이벤트가 발생하려면 플레이어가 다음 조건도 충족해야 합니다.

* 플레이어가 엔티티를  **바라보고**  있어야 합니다. 엔티티는 플레이어 정면의 약 120도 시야각 안에 있어야 합니다.
* 엔티티까지  **시야가 확보되어**  있어야 하며, 그 사이에 아무것도 없어야 합니다.

{% hint style="warning" %}
**📔 참고**: 근접 이벤트는  `maxCameraDistance`를 무시합니다. 카메라의 위치는 영향을 미치지 않습니다. 아바타의 거리, 방향, 시야만 고려됩니다. 커서 이벤트에서 카메라 거리 제한이 어떻게 작동하는지는  [거리 제한](https://docs.decentraland.org/creator/content-creator-ko/sdk7/interactivity/button-events/register-callback.md#distance-limits) 을 참조하세요.
{% endhint %}

## 콜백 제거

근접 콜백을 제거하려면 해당 제거 함수를 사용하세요.

```ts
pointerEventsSystem.removeOnProximityDown(myEntity)
pointerEventsSystem.removeOnProximityUp(myEntity)
pointerEventsSystem.removeOnProximityEnter(myEntity)
pointerEventsSystem.removeOnProximityLeave(myEntity)
```

제거한 후에는 엔티티가 해당 근접 이벤트에 더 이상 반응하지 않습니다.

## 근접 범위 진입 및 이탈

플레이어가 엔티티의 근접 범위에 들어갈 때 콜백을 실행하려면  `pointerEventsSystem.onProximityEnter` 를 사용하고, 범위를 벗어날 때 실행하려면  `pointerEventsSystem.onProximityLeave` 를 사용하세요. 이를 통해 플레이어에게 추가적인 피드백을 제공할 수 있습니다. 예를 들어 아이템과 상호작용할 수 있을 때 소리나 애니메이션을 재생할 수 있습니다.

```ts
pointerEventsSystem.onProximityEnter(
    {
        entity: myEntity,
        opts: {
            button: InputAction.IA_POINTER,
            hoverText: 'Nearby',
            maxDistance: 5,
        },
    },
    function () {
        console.log('Player entered proximity')
    }
)

pointerEventsSystem.onProximityLeave(
    {
        entity: myEntity,
        opts: {
            button: InputAction.IA_POINTER,
            hoverText: 'Nearby',
            maxDistance: 5,
        },
    },
    function () {
        console.log('Player left proximity')
    }
)
```

## 예제: 근접 문

다음 예제에서는 플레이어가 문을 조준할 필요 없이 근처에서 버튼을 누르면 문이 열리거나 닫힙니다.

```ts
const doorPivot = engine.addEntity()
Transform.create(doorPivot, { position: Vector3.create(3, 0, 4) })

const door = engine.addEntity()
GltfContainer.create(door, { src: 'assets/door.glb' })
Transform.create(door, { position: Vector3.create(-1, 0, 0), parent: doorPivot })

let isDoorOpen = false
const closedRot = Quaternion.fromEulerDegrees(0, 0, 0)
const openRot = Quaternion.fromEulerDegrees(0, 90, 0)

pointerEventsSystem.onProximityDown(
    {
        entity: door,
        opts: {
            button: InputAction.IA_PRIMARY,
            hoverText: 'Open / Close',
            maxDistance: 5,
            priority: 1,
        },
    },
    function () {
        if (isDoorOpen) {
            Tween.setRotate(doorPivot, openRot, closedRot, 700)
            isDoorOpen = false
        } else {
            Tween.setRotate(doorPivot, closedRot, openRot, 700)
            isDoorOpen = true
        }
    }
)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.decentraland.org/creator/content-creator-ko/sdk7/interactivity/button-events/proximity-events.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
