> For the complete documentation index, see [llms.txt](https://jorge-jgnz94.gitbook.io/hptk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jorge-jgnz94.gitbook.io/hptk/master/modules/contact-detection.md).

# Contact Detection

![](https://2698598769-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MYpeL-Cll-FXMj9b3XC%2F-MZgFIfY0_IVWMKkuzjz%2F-MZgJ95SnD3Xp2bKuzlu%2FcontactDetectionModel.PNG?alt=media\&token=00a19537-999f-4ef2-a783-8ffa7281b00e)

## Model

ContactDetection module keeps track of contacts between hand's slave representation and contactable Rigidbodies (ContactableViews). It can distinguish hovering, touching and friction-based grabbing. This module requires a Puppet module to be registered in the same part. Variables of this model are described bellow:

#### References

* **Part:** The part whose slave representation will be subject to contact detectio&#x6E;**.** This reference has to be manually set.

#### Control

* **Hover DetectionSystem:** How should hovering be detected?
  * **Overlap Sphere From Root:** ContactableViews inside a sphere with center `ContactDetectionModel.part.root.point.reprs["slave"].transformRef.position` and radius `ContactDetectionModel.sphereCastRadius` will be considered as entered (hovered).
  * **Triggers:** TriggerNotifiers form Pheasy component of slave representation of part's root bone will be used to detect entered (hovered) objects.
* **Sphere Cast Radius:** If using sphere overlap as hover detection system, this value will represent the radius of that sphere.<br>
* **Detect Only These:** If enabled, the list `ContactDetectionModel.bonesToDetect` won't be automatically populated and the existing bones in this list will be the only ones that will be subjected to contact detection.
* **Bones To Detect:** List of bones subjected to contact detection.

#### State

* **Is Entered:** Is some bone hovering some contactable object?
* **Is Touched:** Is some bone touching some contactable object?
* **Is Grasped:** Is the part grasping some contactable object?&#x20;
* **Contacts:** List of detected contacts. Contacts are described in detail [here](/hptk/master/modules/contact-detection/contact.md).

{% hint style="info" %}
**Grasping detection** is only appliable when references part is a **hand (HandModel)**.
{% endhint %}

![](https://2698598769-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MYpeL-Cll-FXMj9b3XC%2F-MZgFIfY0_IVWMKkuzjz%2F-MZgJB2vmfaFuWi2HH7F%2FcontactDetectionView.PNG?alt=media\&token=7aa06c65-dbac-486f-8473-04877534d18e)

## View

#### Events

* **OnFirstEnter:** Emmitted when a bone starts hovering an object while the rest of the bones are not contacting (hovering, touching or grasping) any object.
* **OnEnter:** Emitted when a bone starts hovering some contactable object.<br>
* **OnFirstTouch:** Emmitted when a bone starts touching an object while the rest of the bones are not touching or grasping any object.
* **OnTouch:** Emitted when a bone starts touching some contactable object.<br>
* **OnFirstGrasp:** Emmitted when a bone starts grasping an object while the rest of the bones are not touching or grasping any object.
* **OnGrasp:** Emitted when a bone starts grasping some contactable object.<br>
* **OnUngrasp:** Emitted when a bone stops grasping some contactable object.
* **OnLastUngrasp:** Emmitted when the last bone grasping an object stops doing it.<br>
* **OnUntouch:** Emitted when a bone stops touching some contactable object.
* **OnLastUntouch:** Emmitted when the last bone touching an object stops doing it.<br>
* **OnExit:** Emitted when a bone stops hovering some contactable object.
* **OnLastExit:** Emmitted when the last bone hovering an object stops doing it.
