> For the complete documentation index, see [llms.txt](https://jay07.gitbook.io/portfolio/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jay07.gitbook.io/portfolio/xr-development/inhabit-mechanic.md).

# Inhabit mechanic

In the previous sprint Tirso developed the inhabit mechanic for our game, however we were switching over to OpenXR and a lot of Tirso's code used built-in SteamVR systems. So I mainly had to rewrite the script, although Tirso helped quite a bit.

To summarise what I wanted to do: I basically wanted to fire a line from the player that would change in color if it hovered over an object that it could inhabit, and when it pressed a button it should inhabit the body. Inhabiting would entail gaining that body's abilities, the body I used in the gif below could walk for example.

![](/files/DQmZAkDbLKpMr2SW7CZV)

```
    protected override void OnSelectEntered(SelectEnterEventArgs args)
    {
        InhabitBody(FindXRRig(args.interactor.gameObject));
        base.OnSelectEntered(args);
    }

    private GameObject FindXRRig(GameObject currentObject)
    {
        return currentObject.transform.root.GetComponentInChildren<XRRig>().gameObject;
    }

    private void InhabitBody(GameObject originalXRObject)
    {
        if (!networkPlayer) return;

        originalXRObject.SetActive(false);
        xrRig.SetActive(true);
        networkPlayer.AcquireRig();
    }
```
