Пример #1
0
    private Vector3 FindTarget(ScanMem mem, Vector3 worldPos, out Collider targetCollider)
    {
        targetCollider = null;
        Ray ray = new Ray(direction: (worldPos - mem.shoulder).normalized, origin: mem.shoulder);
        int num = Physics.OverlapCapsuleNonAlloc(ray.origin, worldPos, 0.5f, colliders, motion.grabLayers, QueryTriggerInteraction.Ignore);

        for (int i = 0; i < num; i++)
        {
            Collider     collider            = colliders[i];
            TargetHelper componentInChildren = collider.GetComponentInChildren <TargetHelper>();
            if (componentInChildren != null)
            {
                Vector3 a         = componentInChildren.transform.position - worldPos;
                float   magnitude = (Math3d.ProjectPointOnLineSegment(ray.origin, worldPos, componentInChildren.transform.position) - componentInChildren.transform.position).magnitude;
                if (magnitude < 0.3f && (componentInChildren.transform.position - mem.hand).magnitude < 0.3f)
                {
                    worldPos       = componentInChildren.transform.position;
                    targetCollider = collider;
                }
                else
                {
                    worldPos += a * Mathf.InverseLerp(0.5f, 0.3f, magnitude);
                }
                return(worldPos);
            }
        }
        Vector3 vector = mem.hand + Vector3.ClampMagnitude(worldPos - mem.hand, 0.3f);

        targetCollider = null;
        Vector3 vector2 = vector - mem.pos;
        Ray     ray2    = new Ray(mem.pos, vector2.normalized);

        Debug.DrawRay(ray2.origin, ray2.direction * vector2.magnitude, Color.yellow, 0.2f);
        float   num2    = float.PositiveInfinity;
        Vector3 vector3 = vector;

        for (float num3 = 0.05f; num3 <= 0.5f; num3 += 0.05f)
        {
            if (!Physics.SphereCast(ray2, num3, out RaycastHit hitInfo, vector2.magnitude, motion.grabLayers, QueryTriggerInteraction.Ignore))
            {
                continue;
            }
            float magnitude2 = (vector - hitInfo.point).magnitude;
            magnitude2 += num3 / 10f;
            if (hitInfo.collider.tag == "Target")
            {
                magnitude2 /= 100f;
            }
            else
            {
                if (num3 > 0.2f)
                {
                    continue;
                }
                Vector3 normalized2 = (worldPos - mem.shoulder).normalized;
                Vector3 normalized3 = (hitInfo.point - mem.shoulder).normalized;
                if (Vector3.Dot(normalized2, normalized3) < 0.7f)
                {
                    continue;
                }
            }
            if (magnitude2 < num2)
            {
                num2           = magnitude2;
                vector3        = hitInfo.point;
                targetCollider = hitInfo.collider;
            }
        }
        if (targetCollider != null)
        {
            Vector3 a2         = vector3 - vector;
            float   magnitude3 = (Math3d.ProjectPointOnLineSegment(ray2.origin, vector, vector3) - vector3).magnitude;
            if (targetCollider.tag == "Target")
            {
                if (magnitude3 < 0.2f && (mem.hand - vector3).magnitude < 0.5f)
                {
                    worldPos = vector3;
                }
                else
                {
                    worldPos       = vector + a2 * Mathf.InverseLerp(0.5f, 0.2f, magnitude3);
                    targetCollider = null;
                }
            }
            else if (magnitude3 < 0.1f && a2.magnitude < 0.1f)
            {
                worldPos = vector3;
            }
            else
            {
                worldPos       = vector + a2 * Mathf.InverseLerp(0.2f, 0.1f, magnitude3);
                targetCollider = null;
            }
        }
        mem.pos = vector;
        return(worldPos);
    }
Пример #2
0
    private void ProcessHand(ScanMem mem, HumanSegment arm, HumanSegment forearm, HumanSegment hand, Vector3 worldPos, float extend, bool grab, float animationPhase, bool right)
    {
        double num  = 0.1 + (double)(0.14f * Mathf.Abs(human.controls.targetPitchAngle - mem.grabAngle) / 80f);
        double num2 = num * 2.0;

        if (CheatCodes.climbCheat)
        {
            num2 = (num /= 4.0);
        }
        if (grab && !hand.sensor.grab)
        {
            if ((double)mem.grabTime > num)
            {
                mem.pos = arm.transform.position;
            }
            else
            {
                grab = false;
            }
        }
        if (hand.sensor.grab && !grab)
        {
            mem.grabTime  = 0f;
            mem.grabAngle = human.controls.targetPitchAngle;
        }
        else
        {
            mem.grabTime += Time.fixedDeltaTime;
        }
        hand.sensor.grab = ((double)mem.grabTime > num2 && grab);
        if (extend > 0.2f)
        {
            bool flag = false;
            hand.sensor.targetPosition = worldPos;
            Vector3 vector = worldPos;
            mem.shoulder = arm.transform.position;
            mem.hand     = hand.transform.position;
            if (hand.sensor.grabJoint == null)
            {
                worldPos = FindTarget(mem, worldPos, out hand.sensor.grabFilter);
            }
            PlaceHand(arm, hand, worldPos, active: true, hand.sensor.grabJoint != null, hand.sensor.grabBody);
            if (hand.sensor.grabBody != null)
            {
                LiftBody(hand, hand.sensor.grabBody);
            }
            hand.sensor.grabPosition = worldPos;
        }
        else
        {
            hand.sensor.grabFilter = null;
            if (human.state == HumanState.Walk)
            {
                AnimateHand(arm, forearm, hand, animationPhase, 1f, right);
            }
            else if (human.state == HumanState.FreeFall)
            {
                Vector3 targetDirection = human.targetDirection;
                targetDirection.y = 0f;
                HumanMotion2.AlignToVector(arm, arm.transform.up, -targetDirection, 2f);
                HumanMotion2.AlignToVector(forearm, forearm.transform.up, targetDirection, 2f);
            }
            else
            {
                Vector3 targetDirection2 = human.targetDirection;
                targetDirection2.y = 0f;
                HumanMotion2.AlignToVector(arm, arm.transform.up, -targetDirection2, 20f);
                HumanMotion2.AlignToVector(forearm, forearm.transform.up, targetDirection2, 20f);
            }
        }
    }