예제 #1
0
    // open muscle fully
    void ExtendMuscle(DogLeg leg, Muscles muscle, float amount = 1f)
    {
        float tempBonus = 0;

        if (leg.name.Contains("bl") || leg.name.Contains("br"))
        {
            tempBonus += backLegBonus;
        }
        else
        {
            tempBonus += frontLegBonus;
        }

        switch (muscle)
        {
        case Muscles.Biceps:
            DogLeg.Contract(leg.biceps, -(1 - leg.GetMuscleLength(leg.biceps)) * (bicepsFullContractForce + tempBonus) * amount);
            break;

        case Muscles.Triceps:

            DogLeg.Contract(leg.triceps, -(1 - leg.GetMuscleLength(leg.triceps)) * (tricepsFullContractForce + tempBonus) * amount);

            break;

        case Muscles.Chest:
            DogLeg.Contract(leg.chest, -(1 - leg.GetMuscleLength(leg.chest)) * (chestFullContractForce + tempBonus) * amount);
            break;
        }
    }
예제 #2
0
    void IdleLeg(int i, float idleForce = -100)
    {
        if (idleForce == -100)
        {
            idleForce = _idleForce;
        }

        // calculate the difference of balance from initial rotation
        float currentL = legs[i].lowerLeg.rotation.eulerAngles.x;

        if (currentL > 180)
        {
            currentL = currentL - 360;
        }
        float targetL = legs[i].lowerLegTargetRotation.eulerAngles.x;

        if (targetL > 180)
        {
            targetL = targetL - 360;
        }
        // the difference of balance
        float deltaL = currentL - targetL;

        // reposition the legs according to their muscles
        if (i <= 1)
        {
            DogLeg.Contract(legs[i].biceps, -deltaL * idleForce);
        }
        else
        {
            DogLeg.Contract(legs[i].biceps, deltaL * idleForce);
        }

        // same but with triceps
        float currentU = legs[i].transform.rotation.eulerAngles.x;

        if (currentU > 180)
        {
            currentU = currentU - 360;
        }
        float targetU = legs[i].targetRotation.eulerAngles.x;

        if (targetU > 180)
        {
            targetU = targetU - 360;
        }
        // the difference of balance
        float deltaU = currentU - targetU;

        if (i <= 1)
        {
            DogLeg.Contract(legs[i].triceps, deltaU * idleForce);
        }
        else
        {
            DogLeg.Contract(legs[i].triceps, -deltaU * idleForce);
        }
    }
예제 #3
0
 IEnumerator Step(DogLeg leg, float phase)
 {
     while (true)
     {
         DogLeg.Contract(leg.biceps, Mathf.Sin(phase) * amountEachLeg);
         DogLeg.Contract(leg.triceps, Mathf.Sin(phase + phaseShift * Mathf.Deg2Rad) * amountEachLeg);
         phase += speed * Mathf.Deg2Rad;
         yield return(new WaitForFixedUpdate());
     }
 }
예제 #4
0
    void ExtendLeg(DogLeg leg, float amount)
    {
        float tempBonus = 0;

        if (leg.name.Contains("bl") || leg.name.Contains("br"))
        {
            tempBonus += backLegBonus;
        }
        else
        {
            tempBonus += frontLegBonus;
        }

        DogLeg.Contract(leg.biceps, (1 - leg.GetMuscleLength(leg.biceps)) * amount * (bicepsFullContractForce + tempBonus));

        DogLeg.Contract(leg.triceps, leg.GetMuscleLength(leg.triceps) * amount * (tricepsFullContractForce + tempBonus));
    }
예제 #5
0
    // get leg close to body slowly like a nannypussy
    void ContractLeg(DogLeg leg, float amount)
    {
        float tempBonus = 0;

        if (leg.name.Contains("bl") || leg.name.Contains("br"))
        {
            tempBonus += backLegBonus;
        }
        else
        {
            tempBonus += frontLegBonus;
        }

        // previously I tested here if the triceps was longer or shorter than the biceps, to have a async kind of contraction
        DogLeg.Contract(leg.biceps, leg.GetMuscleLength(leg.biceps) * amount * (bicepsFullContractForce + tempBonus));

        DogLeg.Contract(leg.triceps, leg.GetMuscleLength(leg.triceps) * amount * (tricepsFullContractForce + tempBonus));
    }
예제 #6
0
    void Update2()
    {
        // biceps-triceps, front-back, left-right.
        float[,,] joy = new float[2, 2, 2];

        for (int i = 0; i < 2; i++)
        {
            for (int j = 0; j < 2; j++)
            {
                for (int k = 0; k < 2; k++)
                {
                    // biceps contractions
                    //			 are done on both x axes

                    //           if left controller, invert x axis, so biceps are closed toward inside of controller and open towards outside
                    joy[0, j, k] = (k == 0 ? -1 : 1) * Input.GetAxis("Player 1 " + (k == 0? "left" : "right") + " X") * 3;

                    // triceps

                    //          if left controller, control front legs, if right controller, control back legs
                    joy[1, j, k] = Input.GetAxis("Player 1 " + (j == 0 ? "left" : "right") + " Y");


                    joy[i, j, k] *= moveSpeed;
                    // axis: Player 1 left X
                    //       Player 2 right Y
                }
            }
        }

        DogLeg.Contract(legs[0].biceps, joy[0, 0, 0]);
        DogLeg.Contract(legs[1].biceps, joy[0, 0, 1]);
        DogLeg.Contract(legs[2].biceps, joy[0, 1, 0]);
        DogLeg.Contract(legs[3].biceps, joy[0, 1, 1]);

        DogLeg.Contract(legs[0].triceps, joy[1, 0, 0]);
        DogLeg.Contract(legs[1].triceps, joy[1, 0, 1]);
        DogLeg.Contract(legs[2].triceps, joy[1, 1, 0]);
        DogLeg.Contract(legs[3].triceps, joy[1, 1, 1]);
    }
예제 #7
0
    IEnumerator Idle()
    {
        while (true)
        {
            //Vector3 delta = transform.FindChild("Body").rigidbody.centerOfMass - transform.FindChild("Body").position;

            // code to keep legs straight, close to their initial rotation
            // only works if the body is upright and not tilted in any way.
            float rotZDelta = transform.FindChild("Body").GetComponent <RotationInfo>().rotationZDelta;
            if (Mathf.Abs(rotZDelta) < 30)
            {
                for (int i = 0; i < 2; i++)
                {
                    float currentL = legs[i].lowerLeg.rotation.eulerAngles.x;
                    if (currentL > 180)
                    {
                        currentL = currentL - 360;
                    }
                    float targetL = legs[i].lowerLegTargetRotation.eulerAngles.x;
                    if (targetL > 180)
                    {
                        targetL = targetL - 360;
                    }
                    // the difference of balance
                    float deltaL = currentL - targetL;

                    if (i <= 1)
                    {
                        DogLeg.Contract(legs[i].biceps, -deltaL * idleForce);
                    }
                    else
                    {
                        DogLeg.Contract(legs[i].biceps, deltaL * idleForce);
                    }


                    float currentU = legs[i].transform.rotation.eulerAngles.x;
                    if (currentU > 180)
                    {
                        currentU = currentU - 360;
                    }
                    float targetU = legs[i].targetRotation.eulerAngles.x;
                    if (targetU > 180)
                    {
                        targetU = targetU - 360;
                    }
                    // the difference of balance
                    float deltaU = currentU - targetU;

                    if (i <= 1)
                    {
                        DogLeg.Contract(legs[i].triceps, deltaU * idleForce);
                    }
                    else
                    {
                        DogLeg.Contract(legs[i].triceps, -deltaU * idleForce);
                    }
                }
            }            // end if body not tilted
            else if (Mathf.Abs(rotZDelta) < 150)
            {
                // barrel roll around doggy

                // instead of this how about using chest muscles?
                transform.FindChild("Body").rigidbody.AddTorque(new Vector3(0, 0, -rotZDelta * barrelRollForce));
            }
            else
            {
                // don't do anything
            }

            yield return(0);
            // contract muscles, extend, etc so that everything looks dandy and nice
        }
    }