예제 #1
0
    private bool GetTargetPoint(out Vector3 targetPoint)
    {
        var closestCollider = TargetPicker.PickClosest(
            TargetPickerBounds, armIKController.SymmetricalPosition(NoTargetAnchor.position),
            colliders => {
            // Prefer to grab player body parts.
            var playerColliders = colliders
                                  .Where(c => (c.gameObject.layer & playerLayerMask) != 0);

            if (playerColliders.Any())
            {
                colliders = playerColliders;
            }

            // Try to find at least collider with rigidbody.
            var rigidbodyColliders = colliders
                                     .Where(c => c.rigidbody != null);

            if (rigidbodyColliders.Any())
            {
                colliders = rigidbodyColliders;
            }
            else
            {
                colliders = Enumerable.Empty <Collider> ();
            }

            return(colliders);
        }, out targetPoint
            );

        return(closestCollider != null);
    }
예제 #2
0
    void FixedUpdate()
    {
        Vector3 closestPoint;

        var closestCollider = TargetPicker.PickClosest(
            TargetPickerBounds, armIKController.SymmetricalPosition(NoTargetAnchor.position),                //armIKController.WristWorldAnchor,
            colliders => {
            // Prefer to grab player body parts.
            var playerColliders = colliders
                                  .Where(c => (c.gameObject.layer & playerLayerMask) != 0);

            if (playerColliders.Any())
            {
                colliders = playerColliders;
            }

            // Prefer colliders with rigidbody attached over static.
            var rigidbodyColliders = colliders
                                     .Where(c => c.attachedRigidbody != null);

            if (rigidbodyColliders.Any())
            {
                colliders = rigidbodyColliders;
            }

            return(colliders);
        }, out closestPoint
            );

        if (closestCollider != null)
        {
            // Stretch arm toward closest point on suitable collider.
            armIKController.WristTargetPosition = closestPoint;
        }
        else
        {
            // Stretch arm forward.
            armIKController.WristTargetPosition = armIKController.SymmetricalPosition(NoTargetAnchor.position);
        }
    }