Пример #1
0
    void FixedUpdate()
    {
        if (CurrentState == State.Bending)
        {
            float bendTimeElapsed = Time.fixedTime - bendTimeStart;

            if (bendTimeElapsed > BendMaxTime)
            {
                CurrentState   = State.Punching;
                punchTimeStart = Time.fixedTime;
            }
            else
            {
                // Bend arm.
                armIKController.WristTargetPosition = armIKController.SymmetricalPosition(BendAnchor.position);
            }
        }
        else           /*if ( CurrentState == State.Punching )*/
        {
            float punchTimeElapsed = Time.fixedTime - punchTimeStart;

            if (punchTimeElapsed > PunchMaxTime)
            {
                // Punching is done.
                ActionCompleted = true;
            }
            else
            {
                // Rapidly stretch arm towards the target.
                Vector3 targetPoint;

                if (!GetTargetPoint(out targetPoint))
                {
                    targetPoint = armIKController.SymmetricalPosition(NoTargetAnchor.position);
                }

                var hitDir = (targetPoint - armIKController.SymmetricalPosition(BendAnchor.position)).normalized;
                targetPoint += hitDir * armIKController.ArmLength;

                armIKController.WristTargetPosition = targetPoint;
            }
        }
    }
Пример #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);
        }
    }
Пример #3
0
 void FixedUpdate()
 {
     armIKController.WristTargetPosition = armIKController.SymmetricalPosition(RaiseAnchor.position);
 }