Beispiel #1
0
    public void moveArmBase(
        PhysicsRemoteFPSAgentController controller,
        float height,
        float unitsPerSecond,
        float fixedDeltaTime = 0.02f,
        bool returnToStartPositionIfFailed = false,
        bool disableRendering = false
        )
    {
        // clearing out colliders here since OnTriggerExit is not consistently called in Editor
        collisionListener.Reset();

        // first check if the target position is within bounds of the agent's capsule center/height extents
        // if not, actionFinished false with error message listing valid range defined by extents
        CapsuleCollider cc        = controller.GetComponent <CapsuleCollider>();
        Vector3         cc_center = cc.center;
        Vector3         cc_maxY   = cc.center + new Vector3(0, cc.height / 2f, 0);
        Vector3         cc_minY   = cc.center + new Vector3(0, (-cc.height / 2f) / 2f, 0); // this is halved to prevent arm clipping into floor

        // linear function that take height and adjusts targetY relative to min/max extents
        float targetY = ((cc_maxY.y - cc_minY.y) * (height)) + cc_minY.y;

        Vector3 target = new Vector3(this.transform.localPosition.x, targetY, 0);

        IEnumerator moveCall = ContinuousMovement.move(
            controller: controller,
            collisionListener: collisionListener,
            moveTransform: this.transform,
            targetPosition: target,
            fixedDeltaTime: disableRendering ? fixedDeltaTime : Time.fixedDeltaTime,
            unitsPerSecond: unitsPerSecond,
            returnToStartPropIfFailed: returnToStartPositionIfFailed,
            localPosition: true
            );

        if (disableRendering)
        {
            controller.unrollSimulatePhysics(
                enumerator: moveCall,
                fixedDeltaTime: fixedDeltaTime
                );
        }
        else
        {
            StartCoroutine(moveCall);
        }
    }