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.

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

Last updated

Was this helpful?