Esempio n. 1
0
 void Start()
 {
     WristCollisionDispatcher.TriggerEnter += wrist_OnCollisionEnterEvent;
     WristCollisionDispatcher.TriggerStay  += wrist_OnCollisionEnterEvent;
     armIKController         = GetComponent <ArmIKController> ();
     muscleTensionController = GetComponent <MuscleTensionController> ();
 }
Esempio n. 2
0
    void OnDisable()
    {
        armIKController.RaiseElbowAtFixedAngle = false;

        MuscleTensionController.Relax(muscleTensionController);
        armIKController.enabled = false;
    }
Esempio n. 3
0
    void OnEnable()
    {
        MuscleTensionController.Stretch(muscleTensionController);

        if (armIKController != null)
        {
            armIKController.enabled = true;
        }
    }
Esempio n. 4
0
 public static void Relax(
     MuscleTensionController controller,
     float forceMultiplier = 0, float damperMultiplier = 0, bool useGravity = true
     )
 {
     if (controller != null)
     {
         controller.SetValues(forceMultiplier, damperMultiplier, useGravity);
     }
 }
Esempio n. 5
0
 public static void Stretch(
     MuscleTensionController controller,
     float forceMultiplier = 1, float damperMultiplier = 1, bool useGravity = false
     )
 {
     if (controller != null)
     {
         controller.SetValues(forceMultiplier, damperMultiplier, useGravity);
     }
 }
Esempio n. 6
0
    private void PerformRelease()
    {
        if (IsGrabbing)
        {
            Destroy(fixedJoint);
            fixedJoint      = null;
            GrabbedCollider = null;
        }

        WantsToGrab = false;
        MuscleTensionController.Relax(muscleTensionController);
        armIKController.enabled = false;
    }
Esempio n. 7
0
    private void PerformStartGrabbing()
    {
        if (IsGrabbing)
        {
            PerformRelease();
        }

        WantsToGrab = true;

        MuscleTensionController.Stretch(muscleTensionController);

        if (armIKController != null)
        {
            armIKController.enabled = true;
        }
    }
Esempio n. 8
0
    void wrist_OnCollisionEnterEvent(GameObject sender, Collider otherCollider)
    {
        if (WantsToGrab)
        {
            // Fix position, allow rotation.
            fixedJoint = LowerArm.AddComponent <ConfigurableJoint> ();
            fixedJoint.connectedBody = otherCollider.attachedRigidbody;
            fixedJoint.xMotion       = ConfigurableJointMotion.Locked;
            fixedJoint.yMotion       = ConfigurableJointMotion.Locked;
            fixedJoint.zMotion       = ConfigurableJointMotion.Locked;
            fixedJoint.breakForce    = BreakForce;
            fixedJoint.breakTorque   = BreakTorque;
            fixedJoint.anchor        = GrabAnchor;

            GrabbedCollider = otherCollider;
            WantsToGrab     = false;
            MuscleTensionController.Relax(muscleTensionController);
            armIKController.enabled = false;
        }
    }
Esempio n. 9
0
    void OnEnable()
    {
        bendTimeStart   = Time.fixedTime;
        CurrentState    = State.Bending;
        ActionCompleted = false;

        // TODO: get components in Awake rather than Start. This check should be removed after.
        if (armIKController != null)
        {
            armIKController.RaiseElbowAtFixedAngle = true;
            armIKController.RaiseElbowAngle        = RaiseElbowAngle;
        }

        MuscleTensionController.Stretch(muscleTensionController, ForceMultiplier, DamperMultiplier);

        // TODO: get components in Awake rather than Start. This check should be removed after.
        if (armIKController != null)
        {
            armIKController.enabled = true;
        }
    }
Esempio n. 10
0
 void Start()
 {
     LowerArmCollisionDispatcher.CollisionEnter += lowerArm_OnCollisionEnterEvent;
     armIKController         = GetComponent <ArmIKController> ();
     muscleTensionController = GetComponent <MuscleTensionController> ();
 }
Esempio n. 11
0
 void OnDisable()
 {
     MuscleTensionController.Relax(muscleTensionController);
     armIKController.enabled = false;
 }
Esempio n. 12
0
 void Start()
 {
     armIKController         = GetComponent <ArmIKController> ();
     muscleTensionController = GetComponent <MuscleTensionController> ();
 }
Esempio n. 13
0
    void FixedUpdate()
    {
        TrackContacts();

        float timeSinceLastGrounded = Time.fixedTime - lastGroundedTimestamp;
        bool  readyToJump           = Time.fixedTime - lastJumpTimestamp >= JumpCooldown;
        var   move       = new Vector3(MoveX, 0, MoveY);
        var   m          = collider.material;
        float moveAmount = move.magnitude;

        if (moveAmount != 0)
        {
            m.dynamicFriction = 0;
            m.frictionCombine = PhysicMaterialCombine.Average;

            m.dynamicFriction2   = SidewaysFriction;
            m.staticFriction2    = SidewaysFriction;
            m.frictionDirection2 = transform.InverseTransformDirection(Vector3.Cross(move, Vector3.up));

            rigidbody.WakeUp();

            var moveDir = move.normalized;

            if (moveAmount > 1)
            {
                moveAmount = 1;
            }

            var platformVelocity = Vector3.zero;
            var horzAccel        = moveDir * moveAmount;
            var vertAccel        = Vector3.up * moveAmount;

            if (IsGrounded)
            {
                var otherRigidbody = floorContact.otherCollider.attachedRigidbody;

                if (otherRigidbody != null)
                {
                    platformVelocity = otherRigidbody.GetPointVelocity(floorContact.point);
                }

                if (PerformJump && readyToJump)
                {
                    horzAccel *= JumpHorizontalAcceleration;
                    // In this case vertical acceleration added by separate AddForce () call.
                }
                else
                {
                    horzAccel *= HorizontalAcceleration;
                    vertAccel *= VerticalAcceleration;
                }
            }
            else
            {
                horzAccel *= AirHorizontalAcceleration;
                vertAccel *= AirVerticalAcceleration;
            }

            var relVelocity     = rigidbody.velocity - platformVelocity;
            var relHorzVelocity = new Vector3(relVelocity.x, 0, relVelocity.z);

            if (relHorzVelocity.magnitude > MaxVelocity)
            {
                var accelProj = Vector3.Project(horzAccel, relHorzVelocity.normalized);                         // TODO: is ".normalized" necessary?
                horzAccel -= accelProj;
            }

            var totalAccel = horzAccel + vertAccel;
            rigidbody.AddForce(totalAccel * totalBodyMass, ForceMode.Force);

            if (timeSinceLastGrounded < AirControlLossDelay || IsGrabbing)
            {
                maintainOrientationJoint.TargetRotation = Quaternion.RotateTowards(
                    maintainOrientationJoint.TargetRotation,
                    Quaternion.Inverse(Quaternion.LookRotation(moveDir)),
                    RotateVelocity * Time.fixedDeltaTime
                    );
            }
        }
        else
        {
            m.dynamicFriction = IdleFriction;
            m.frictionCombine = PhysicMaterialCombine.Maximum;

            m.dynamicFriction2   = 0;
            m.staticFriction2    = 0;
            m.frictionDirection2 = Vector3.zero;
        }

        collider.material = m;

        if (PerformJump && IsGrounded && readyToJump)
        {
            var   normalInPelvisCoords = transform.InverseTransformDirection(floorContact.normal);
            float jumpAmount           = Mathf.Clamp01(Vector3.Dot(normalInPelvisCoords, Vector3.up));

            if (jumpAmount > 0)
            {
                var accel = Vector3.up * JumpVerticalAcceleration * jumpAmount;
                rigidbody.AddForce(accel * totalBodyMass, ForceMode.Force);
                lastJumpTimestamp = Time.fixedTime;
            }
        }

        if (PerformCrouch)
        {
            MuscleTensionController.Relax(muscleTensionController, damperMultiplier: 0.01f);
        }
        else
        {
            if (IsGrounded || timeSinceLastGrounded < AirControlLossDelay)
            {
                MuscleTensionController.Stretch(muscleTensionController, useGravity: true);
            }
            else if (IsGrabbing)
            {
                MuscleTensionController.Stretch(muscleTensionController, 0.1f, 0.1f, useGravity: true);
            }
            else
            {
                MuscleTensionController.Relax(muscleTensionController, damperMultiplier: 0.1f);
            }
        }
    }
Esempio n. 14
0
 void Awake()
 {
     muscleTensionController  = GetComponent <MuscleTensionController> ();
     maintainOrientationJoint = GetComponent <MaintainOrientationJoint> ();
 }