# 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.

![](https://708397551-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MjnIU3pkRtiaeZ6PEEt%2Fuploads%2FvnVjei1dvnRvqiLzIG1u%2FAnimatie.gif?alt=media\&token=b584990c-e574-4339-9746-76e1369eaae9)

```
    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();
    }
```

