private IEnumerator Sit()
    {
        Controller.Signal signal      = Controller.GetSignal("Sit");
        Interaction       interaction = Controller.ProjectionInteraction != null ? Controller.ProjectionInteraction : Controller.GetClosestInteraction(transform);

        float threshold = 0.25f;

        if (interaction != null)
        {
            Controller.ActiveInteraction = interaction;
            IsInteracting = true;
            while (signal.Query())
            {
                ApplyStaticGoal(interaction.GetContact("Hips").GetPosition(), interaction.GetContact("Hips").GetForward(), Signals);
                Geometry.Setup(Geometry.Resolution);
                Geometry.Sense(interaction.GetCenter(), LayerMask.GetMask("Interaction"), interaction.GetExtents(), InteractionSmoothing);
                yield return(new WaitForSeconds(0f));
            }
            while (StyleSeries.GetStyle(TimeSeries.Pivot, "Sit") > threshold)
            {
                ApplyDynamicGoal(
                    RootSeries.Transformations[TimeSeries.Pivot],
                    Controller.QueryMove(KeyCode.W, KeyCode.S, KeyCode.A, KeyCode.D, Signals),
                    Controller.QueryTurn(KeyCode.Q, KeyCode.E, 90f),
                    Signals
                    );
                Geometry.Setup(Geometry.Resolution);
                Geometry.Sense(interaction.GetCenter(), LayerMask.GetMask("Interaction"), interaction.GetExtents(), InteractionSmoothing);
                yield return(new WaitForSeconds(0f));
            }
            IsInteracting = false;
            Controller.ActiveInteraction = null;
        }
    }
    private IEnumerator Open()
    {
        Controller.Signal signal      = Controller.GetSignal("Open");
        Interaction       interaction = Controller.ProjectionInteraction != null ? Controller.ProjectionInteraction : Controller.GetClosestInteraction(transform);

        if (interaction != null)
        {
            Controller.ActiveInteraction = interaction;
            IsInteracting = true;
            while (signal.Query())
            {
                ApplyStaticGoal(interaction.GetCenter().GetPosition(), interaction.GetCenter().GetForward(), Signals);
                Geometry.Setup(Geometry.Resolution);
                Geometry.Sense(interaction.GetCenter(), LayerMask.GetMask("Interaction"), interaction.GetExtents(), InteractionSmoothing);
                yield return(new WaitForSeconds(0f));
            }
            IsInteracting = false;
            Controller.ActiveInteraction = null;
        }
    }
    private IEnumerator Carry()
    {
        Controller.Signal signal      = Controller.GetSignal("Carry");
        Interaction       interaction = Controller.ProjectionInteraction != null ? Controller.ProjectionInteraction : Controller.GetClosestInteraction(transform);

        if (interaction != null)
        {
            Controller.ActiveInteraction = interaction;
            // Debug.Log("Carrying started...");
            IsInteracting = true;

            float duration  = 0.5f;
            float threshold = 0.2f;

            Vector3    deltaPos = new Vector3(0f, -0.15f, 0.2f);
            Quaternion deltaRot = Quaternion.Euler(-30f, 0f, 0f);

            float height = 1f;

            Matrix4x4 GetObjectMatrix(float staticness)
            {
                Matrix4x4 right = Actor.GetBoneTransformation("RightWrist");
                Matrix4x4 left  = Actor.GetBoneTransformation("LeftWrist");

                Quaternion rotation = Quaternion.Slerp(
                    Quaternion.LookRotation(left.GetRight(), left.GetForward()),
                    Quaternion.LookRotation(-right.GetRight(), right.GetForward()),
                    0.5f
                    );

                rotation *= deltaRot;
                rotation  = Quaternion.Slerp(
                    rotation,
                    transform.rotation,
                    Utility.Normalise(staticness, 0f, 1f, 0.5f, 1f)
                    );

                return(Matrix4x4.TRS(
                           Vector3.Lerp(left.GetPosition(), right.GetPosition(), 0.5f) + rotation * deltaPos,
                           rotation,
                           interaction.transform.lossyScale
                           ));
            }

            bool HasContact()
            {
                float left  = ContactSeries.GetContact(TimeSeries.Pivot, "LeftWrist");
                float right = ContactSeries.GetContact(TimeSeries.Pivot, "RightWrist");

                return(right > 0.5f && left > 0.5f || (left + right) > 1f);
            }

            //Move to the target location
            // Debug.Log("Approaching to lift object...");
            while (signal.Query())
            {
                ApplyStaticGoal(interaction.GetCenter().GetPosition(), interaction.GetCenter().GetForward(), Controller.PoolSignals());
                Geometry.Setup(Geometry.Resolution);
                Geometry.Sense(interaction.GetCenter(), LayerMask.GetMask("Interaction"), interaction.GetExtents(), InteractionSmoothing);
                Geometry.Retransform(interaction.GetOrigin(GoalSeries.Transformations[TimeSeries.Pivot]));
                if (Vector3.Distance(GetObjectMatrix(0f).GetPosition(), interaction.transform.position) < threshold)
                {
                    break;
                }
                yield return(new WaitForSeconds(0f));
            }

            //Move the object from the surface to the hands
            // Debug.Log("Picking object...");
            float      tPick = Time.time;
            Vector3    pos   = interaction.transform.position;
            Quaternion rot   = interaction.transform.rotation;
            while (signal.Query() && HasContact())
            {
                float     ratio = Mathf.Clamp((Time.time - tPick) / duration, 0f, 1f);
                Matrix4x4 m     = GetObjectMatrix(1f - ratio);
                interaction.transform.position = Vector3.Lerp(pos, m.GetPosition(), ratio);
                interaction.transform.rotation = Quaternion.Slerp(rot, m.GetRotation(), ratio);
                ApplyStaticGoal(interaction.GetCenter().GetPosition(), interaction.GetCenter().GetForward(), Controller.PoolSignals());
                Geometry.Setup(Geometry.Resolution);
                Geometry.Sense(interaction.GetCenter(), LayerMask.GetMask("Interaction"), interaction.GetExtents(), InteractionSmoothing);
                Geometry.Retransform(interaction.GetOrigin(GoalSeries.Transformations[TimeSeries.Pivot]));
                if (ratio >= 1f)
                {
                    break;
                }
                yield return(new WaitForSeconds(0f));
            }

            //Move around with the object
            // Debug.Log("Carrying object and moving...");
            while (signal.Query() && HasContact())
            {
                Matrix4x4 m = GetObjectMatrix(0f);
                interaction.transform.position = m.GetPosition();
                interaction.transform.rotation = m.GetRotation();
                ApplyDynamicGoal(
                    interaction.GetCenter(),
                    Controller.QueryMove(KeyCode.W, KeyCode.S, KeyCode.A, KeyCode.D, Signals) + new Vector3(0f, height - interaction.transform.position.y, 0f),
                    Controller.QueryTurn(KeyCode.Q, KeyCode.E, 90f),
                    Signals
                    );
                Geometry.Setup(Geometry.Resolution);
                Geometry.Sense(interaction.GetCenter(), LayerMask.GetMask("Interaction"), interaction.GetExtents(), InteractionSmoothing);
                Geometry.Retransform(interaction.GetOrigin(GoalSeries.Transformations[TimeSeries.Pivot]));
                yield return(new WaitForSeconds(0f));
            }

            //Perform motions to start placing the object
            // Debug.Log("Transitioning to placing down object...");
            while (HasContact())
            {
                Matrix4x4 m = GetObjectMatrix(0f);
                interaction.transform.position = m.GetPosition();
                interaction.transform.rotation = m.GetRotation();
                Geometry.Setup(Geometry.Resolution);
                Geometry.Sense(interaction.GetCenter(), LayerMask.GetMask("Interaction"), interaction.GetExtents(), InteractionSmoothing);
                Geometry.Retransform(interaction.GetOrigin(GoalSeries.Transformations[TimeSeries.Pivot]));
                if (Controller.ProjectionActive)
                {
                    ApplyStaticGoal(Controller.Projection.point, Vector3.ProjectOnPlane(Controller.Projection.point - transform.position, Vector3.up).normalized, Signals);
                    if (Vector3.Distance(Controller.Projection.point, interaction.transform.position) < threshold)
                    {
                        break;
                    }
                }
                else
                {
                    Vector3 surface = Utility.ProjectGround(interaction.transform.position, LayerMask.GetMask("Default", "Ground"));
                    ApplyStaticGoal(surface, Vector3.ProjectOnPlane(m.GetForward(), Vector3.up).normalized, Signals);
                    if (Vector3.Distance(surface, interaction.transform.position) < threshold)
                    {
                        break;
                    }
                }
                yield return(new WaitForSeconds(0f));
            }

            //Make sure the object is again placed on the surface
            // Debug.Log("Placing object...");
            float      tPlace    = Time.time;
            Vector3    aPosPlace = interaction.transform.position;
            Vector3    bPosPlace = Utility.ProjectGround(aPosPlace, LayerMask.GetMask("Default", "Ground"));
            Quaternion aRotPlace = interaction.transform.rotation;
            Quaternion bRotPlace = Quaternion.LookRotation(Vector3.ProjectOnPlane(aRotPlace.GetForward(), Vector3.up), Vector3.up);
            while (true)
            {
                float ratio = Mathf.Clamp((Time.time - tPlace) / duration, 0f, 1f);
                interaction.transform.position = Vector3.Lerp(aPosPlace, bPosPlace, ratio);
                interaction.transform.rotation = Quaternion.Slerp(aRotPlace, bRotPlace, ratio);
                Geometry.Setup(Geometry.Resolution);
                Geometry.Sense(interaction.GetCenter(), LayerMask.GetMask("Interaction"), interaction.GetExtents(), InteractionSmoothing);
                Geometry.Retransform(interaction.GetOrigin(GoalSeries.Transformations[TimeSeries.Pivot]));
                ApplyStaticGoal(transform.position, transform.forward, Signals);
                if (ratio >= 1f)
                {
                    break;
                }
                yield return(new WaitForSeconds(0f));
            }

            while (StyleSeries.GetStyle(TimeSeries.Pivot, "Carry") > 0.1)
            {
                ApplyDynamicGoal(
                    RootSeries.Transformations[TimeSeries.Pivot],
                    Controller.QueryMove(KeyCode.W, KeyCode.S, KeyCode.A, KeyCode.D, Signals),
                    Controller.QueryTurn(KeyCode.Q, KeyCode.E, 90f),
                    Signals
                    );
                Geometry.Setup(Geometry.Resolution);
                Geometry.Sense(interaction.GetCenter(), LayerMask.GetMask("Interaction"), interaction.GetExtents(), InteractionSmoothing);
                yield return(new WaitForSeconds(0f));
            }

            IsInteracting = false;
            // Debug.Log("Carrying finished...");
            Controller.ActiveInteraction = null;
        }
    }