Ejemplo n.º 1
0
    public Vector3 ApplyTorsoPose(float torsoTonus, float headTonus, float torsoBend, float lift)
    {
        lift       *= Mathf.Clamp01(timeSinceUnconsious / 3f) * Mathf.Clamp01(timeSinceOffGround * 0.2f + 0.8f);
        torsoTonus *= Mathf.Clamp01(timeSinceUnconsious);
        torsoTonus *= 2f;
        headTonus  *= 2f;
        float num  = human.weight * 0.8f * lift;
        float num2 = human.controls.targetPitchAngle;

        if (human.hasGrabbed)
        {
            num2 = (num2 + 80f) * 0.5f - 80f;
        }
        HumanMotion2.AlignLook(ragdoll.partHead, Quaternion.Euler(num2, human.controls.targetYawAngle, 0f), 2f * headTonus, 10f * headTonus);
        if (human.onGround || human.state == HumanState.Climb)
        {
            torsoBend *= 40f;
            HumanMotion2.AlignLook(ragdoll.partChest, Quaternion.Euler(human.controls.targetPitchAngle + torsoBend, human.controls.targetYawAngle, 0f), 2f * torsoTonus, 10f * torsoTonus);
            HumanMotion2.AlignLook(ragdoll.partWaist, Quaternion.Euler(human.controls.targetPitchAngle + torsoBend / 2f, human.controls.targetYawAngle, 0f), 1f * torsoTonus, 15f * torsoTonus);
            HumanMotion2.AlignLook(ragdoll.partHips, Quaternion.Euler(human.controls.targetPitchAngle, human.controls.targetYawAngle, 0f), 0.5f * torsoTonus, 20f * torsoTonus);
        }
        float num3 = 0f;

        if (human.targetDirection.y > 0f)
        {
            num3 = human.targetDirection.y * 0.25f;
            if (human.onGround && human.ragdoll.partLeftHand.sensor.grabBody != null)
            {
                num3 *= 1.5f;
            }
            if (human.onGround && human.ragdoll.partRightHand.sensor.grabBody != null)
            {
                num3 *= 1.5f;
            }
        }
        else
        {
            num3 = 0f - human.targetDirection.y;
        }
        Vector3 vector  = Mathf.Lerp(0.2f, 0f, num3) * num * headTonus * Vector3.up;
        Vector3 vector2 = Mathf.Lerp(0.6f, 0f, num3) * num * torsoTonus * Vector3.up;
        Vector3 vector3 = Mathf.Lerp(0.2f, 0.5f, num3) * num * torsoTonus * Vector3.up;
        Vector3 vector4 = Mathf.Lerp(0f, 0.5f, num3) * num * torsoTonus * Vector3.up;

        if (human.controls.leftGrab)
        {
            UnblockArmBehindTheBack(ragdoll.partLeftHand, -1f);
        }
        if (human.controls.rightGrab)
        {
            UnblockArmBehindTheBack(ragdoll.partRightHand, 1f);
        }
        ragdoll.partHead.rigidbody.SafeAddForce(vector);
        ragdoll.partChest.rigidbody.SafeAddForce(vector2);
        ragdoll.partWaist.rigidbody.SafeAddForce(vector3);
        ragdoll.partHips.rigidbody.SafeAddForce(vector4);
        StabilizeHorizontal(ragdoll.partHips.rigidbody, ragdoll.partBall.rigidbody, 1f * lift * Mathf.Lerp(1f, 0.25f, Mathf.Abs(num3)));
        StabilizeHorizontal(ragdoll.partHead.rigidbody, ragdoll.partBall.rigidbody, 0.2f * lift * Mathf.Lerp(1f, 0f, Mathf.Abs(num3)));
        return(-(vector + vector2 + vector3 + vector4));
    }
Ejemplo n.º 2
0
 private void OnEnable()
 {
     all.Add(this);
     instance       = this;
     grabManager    = GetComponent <GrabManager>();
     groundManager  = GetComponent <GroundManager>();
     motionControl2 = GetComponent <HumanMotion2>();
     controls       = GetComponentInParent <HumanControls>();
 }
Ejemplo n.º 3
0
 public LegMuscles(Human human, Ragdoll ragdoll, HumanMotion2 motion)
 {
     this.human   = human;
     this.ragdoll = ragdoll;
     this.motion  = motion;
     ballRadius   = (ragdoll.partBall.collider as SphereCollider).radius;
     ballMaterial = ragdoll.partBall.collider.material;
     footMaterial = ragdoll.partLeftFoot.collider.material;
     ballFriction = ballMaterial.staticFriction;
     footFriction = footMaterial.staticFriction;
 }
Ejemplo n.º 4
0
 private void StandAnimation(Vector3 torsoFeedback, float tonus)
 {
     HumanMotion2.AlignToVector(ragdoll.partLeftThigh, -ragdoll.partLeftThigh.transform.up, Vector3.up, 10f * tonus);
     HumanMotion2.AlignToVector(ragdoll.partRightThigh, -ragdoll.partRightThigh.transform.up, Vector3.up, 10f * tonus);
     HumanMotion2.AlignToVector(ragdoll.partLeftLeg, -ragdoll.partLeftLeg.transform.up, Vector3.up, 10f * tonus);
     HumanMotion2.AlignToVector(ragdoll.partRightLeg, -ragdoll.partRightLeg.transform.up, Vector3.up, 10f * tonus);
     ragdoll.partBall.rigidbody.SafeAddForce(torsoFeedback * 0.2f);
     ragdoll.partLeftFoot.rigidbody.SafeAddForce(torsoFeedback * 0.4f);
     ragdoll.partRightFoot.rigidbody.SafeAddForce(torsoFeedback * 0.4f);
     ragdoll.partBall.rigidbody.angularVelocity = Vector3.zero;
 }
Ejemplo n.º 5
0
        public void Align(Rigidbody body, Vector3 pos, Vector3 dir)
        {
            float num = 1f - (pos - base.transform.position).magnitude / radius;

            if (!(num < 0f))
            {
                num = Mathf.Pow(num, power);
                body.AddForceAtPosition(((base.transform.position - pos).normalized * springSnap - body.GetPointVelocity(pos) * body.mass * 1f) * num, pos);
                HumanMotion2.AlignToVector(body, dir, base.transform.forward, springAlign);
            }
        }
Ejemplo n.º 6
0
 private Vector3 AnimateLeg(HumanSegment thigh, HumanSegment leg, HumanSegment foot, float phase, Vector3 torsoFeedback, float tonus)
 {
     tonus *= 20f;
     phase -= Mathf.Floor(phase);
     if (phase < 0.2f)
     {
         HumanMotion2.AlignToVector(thigh, thigh.transform.up, human.controls.walkDirection + Vector3.down, 3f * tonus);
         HumanMotion2.AlignToVector(leg, thigh.transform.up, -human.controls.walkDirection - Vector3.up, tonus);
         Vector3 vector = Vector3.up * 20f;
         foot.rigidbody.SafeAddForce(vector);
         return(-vector);
     }
     if (phase < 0.5f)
     {
         HumanMotion2.AlignToVector(thigh, thigh.transform.up, human.controls.walkDirection, 2f * tonus);
         HumanMotion2.AlignToVector(leg, thigh.transform.up, human.controls.walkDirection, 3f * tonus);
     }
     else
     {
         if (phase < 0.7f)
         {
             Vector3 vector2 = torsoFeedback * 0.2f;
             foot.rigidbody.SafeAddForce(vector2);
             HumanMotion2.AlignToVector(thigh, thigh.transform.up, human.controls.walkDirection + Vector3.down, tonus);
             HumanMotion2.AlignToVector(leg, thigh.transform.up, Vector3.down, tonus);
             return(-vector2);
         }
         if (phase < 0.9f)
         {
             Vector3 vector3 = torsoFeedback * 0.2f;
             foot.rigidbody.SafeAddForce(vector3);
             HumanMotion2.AlignToVector(thigh, thigh.transform.up, -human.controls.walkDirection + Vector3.down, tonus);
             HumanMotion2.AlignToVector(leg, thigh.transform.up, -human.controls.walkDirection + Vector3.down, tonus);
             return(-vector3);
         }
         HumanMotion2.AlignToVector(thigh, thigh.transform.up, -human.controls.walkDirection + Vector3.down, tonus);
         HumanMotion2.AlignToVector(leg, thigh.transform.up, -human.controls.walkDirection, tonus);
     }
     return(Vector3.zero);
 }
Ejemplo n.º 7
0
    private void AnimateHand(HumanSegment arm, HumanSegment forearm, HumanSegment hand, float phase, float tonus, bool right)
    {
        tonus *= 50f * human.controls.walkSpeed;
        phase -= Mathf.Floor(phase);
        Vector3 a      = Quaternion.Euler(0f, human.controls.targetYawAngle, 0f) * Vector3.forward;
        Vector3 vector = Quaternion.Euler(0f, human.controls.targetYawAngle, 0f) * Vector3.right;

        if (!right)
        {
            vector = -vector;
        }
        if (phase < 0.5f)
        {
            HumanMotion2.AlignToVector(arm, arm.transform.up, Vector3.down + vector / 2f, 3f * tonus);
            HumanMotion2.AlignToVector(forearm, forearm.transform.up, a / 2f - vector, 3f * tonus);
        }
        else
        {
            HumanMotion2.AlignToVector(arm, arm.transform.up, -a + vector / 2f, 3f * tonus);
            HumanMotion2.AlignToVector(forearm, forearm.transform.up, a + Vector3.down, 3f * tonus);
        }
    }
Ejemplo n.º 8
0
    private void LiftBody(HumanSegment hand, Rigidbody body)
    {
        if (human.GetComponent <GroundManager>().IsStanding(body.gameObject) || body.tag == "NoLift")
        {
            return;
        }
        float     num       = 0.5f + 0.5f * Mathf.InverseLerp(0f, 100f, body.mass);
        Vector3   vector    = (human.targetLiftDirection.ZeroY() * maxPushForce).SetY(Mathf.Max(0f, human.targetLiftDirection.y) * maxLiftForce);
        float     magnitude = (hand.transform.position - body.worldCenterOfMass).magnitude;
        float     num2      = num;
        float     num3      = 1f;
        float     d         = 1f;
        Carryable component = body.GetComponent <Carryable>();

        if (component != null)
        {
            num2 *= component.liftForceMultiplier;
            num3  = component.forceHalfDistance;
            d     = component.damping;
            if (num3 <= 0f)
            {
                throw new InvalidOperationException("halfdistance cant be 0 or less!");
            }
        }
        float num4 = num3 / (num3 + magnitude);

        vector *= num2;
        vector *= num4;
        body.SafeAddForce(vector);
        hand.rigidbody.SafeAddForce(-vector * 0.5f);
        ragdoll.partChest.rigidbody.SafeAddForce(-vector * 0.5f);
        body.SafeAddTorque(-body.angularVelocity * liftDamp * d, ForceMode.Acceleration);
        body.SafeAddTorque(-body.angularVelocity.normalized * body.angularVelocity.sqrMagnitude * liftDampSqr * d, ForceMode.Acceleration);
        if (!(component != null) || component.aiming == CarryableAiming.None)
        {
            return;
        }
        Vector3 vector2 = human.targetLiftDirection;

        if (component.limitAlignToHorizontal)
        {
            vector2.y = 0f;
            vector2.Normalize();
        }
        Vector3 vector3   = (component.aiming != CarryableAiming.ForwardAxis) ? (body.worldCenterOfMass - hand.transform.position).normalized : body.transform.forward;
        float   aimSpring = component.aimSpring;
        float   num5      = (!(component.aimTorque < float.PositiveInfinity)) ? aimSpring : component.aimTorque;

        if (!component.alwaysForward)
        {
            float num6 = Vector3.Dot(vector3, vector2);
            if (num6 < 0f)
            {
                vector2 = -vector2;
                num6    = 0f - num6;
            }
            num5 *= Mathf.Pow(num6, component.aimAnglePower);
        }
        else
        {
            float num7 = Vector3.Dot(vector3, vector2);
            num7  = 0.5f + num7 / 2f;
            num5 *= Mathf.Pow(num7, component.aimAnglePower);
        }
        if (component.aimDistPower != 0f)
        {
            num5 *= Mathf.Pow((body.worldCenterOfMass - hand.transform.position).magnitude, component.aimDistPower);
        }
        HumanMotion2.AlignToVector(body, vector3, vector2, aimSpring, num5);
    }
Ejemplo n.º 9
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);
            }
        }
    }
Ejemplo n.º 10
0
 public HandMuscles(Human human, Ragdoll ragdoll, HumanMotion2 motion)
 {
     this.human   = human;
     this.ragdoll = ragdoll;
     this.motion  = motion;
 }
Ejemplo n.º 11
0
    private void ProcessHand(HandMuscles.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(this.human.controls.targetPitchAngle - mem.grabAngle) / 80f);
        double num2 = num * 2.0;

        if (CheatCodes.climbCheat)
        {
            num = (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 = this.human.controls.targetPitchAngle;
        }
        else
        {
            mem.grabTime += Time.fixedDeltaTime;
        }
        hand.sensor.grab = ((double)mem.grabTime > num2 && grab);
        if (this.human.mod_vo.isBoxing && extend < 0.2f)
        {
            hand.sensor.targetPosition = worldPos;
            mem.shoulder       = arm.transform.position;
            mem.hand           = hand.transform.position;
            this.maxPushForce *= 3f;
            if (hand.sensor.grabJoint == null)
            {
                worldPos = this.FindTarget(mem, worldPos, out hand.sensor.grabFilter);
            }
            this.PlaceHand(arm, hand, worldPos, true, hand.sensor.grabJoint != null, hand.sensor.grabBody);
            if (hand.sensor.grabBody != null)
            {
                this.LiftBody(hand, hand.sensor.grabBody);
            }
            hand.sensor.grabPosition = worldPos;
            return;
        }
        if (extend > 0.2f)
        {
            hand.sensor.targetPosition = worldPos;
            mem.shoulder = arm.transform.position;
            mem.hand     = hand.transform.position;
            if (hand.sensor.grabJoint == null)
            {
                worldPos = this.FindTarget(mem, worldPos, out hand.sensor.grabFilter);
            }
            this.PlaceHand(arm, hand, worldPos, true, hand.sensor.grabJoint != null, hand.sensor.grabBody);
            if (hand.sensor.grabBody != null)
            {
                this.LiftBody(hand, hand.sensor.grabBody);
            }
            hand.sensor.grabPosition = worldPos;
            return;
        }
        hand.sensor.grabFilter = null;
        if (this.human.state == HumanState.Walk)
        {
            this.AnimateHand(arm, forearm, hand, animationPhase, 1f, right);
            return;
        }
        if (this.human.state == HumanState.FreeFall)
        {
            Vector3 targetDirection = this.human.targetDirection;
            targetDirection.y = 0f;
            HumanMotion2.AlignToVector(arm, arm.transform.up, -targetDirection, 2f);
            HumanMotion2.AlignToVector(forearm, forearm.transform.up, targetDirection, 2f);
            return;
        }
        if (this.human.mod_vo.isBoxing)
        {
            return;
        }
        Vector3 targetDirection2 = this.human.targetDirection;

        targetDirection2.y = 0f;
        HumanMotion2.AlignToVector(arm, arm.transform.up, -targetDirection2, 20f);
        HumanMotion2.AlignToVector(forearm, forearm.transform.up, targetDirection2, 20f);
    }