Ejemplo n.º 1
0
    private void PerformSimpleControlScheme(ContactPointInfo info, float horizontal, float vertical)
    {
        float timeAllowed = 1.2f;
        float timePassed  = info.hitTime - Time.timeSinceLevelLoad;
        float x           = 1.0f - Mathf.Sqrt(Mathf.Clamp01(timePassed / timeAllowed));
        float forceAmount = 800f;

        forceAmount += x * forceAmount;
        Vector3 direction = GetSimpleDirection(info.surfaceNormal, horizontal, vertical);

        if (timePassed < recalculateHitTime)
        {
            rb.AddForce(direction * forceAmount);
        }
    }
Ejemplo n.º 2
0
    private void FireEvent(ContactPointInfo info, float horizontal, float vertical)
    {
        if (airing)
        {
            return;
        }

        switch (controlScheme)
        {
        case ControlScheme.Original:
            PerformOriginalControlScheme(info, horizontal, vertical);
            break;

        case ControlScheme.Simple:
            //print("performing jump, surface is: " + collidingWith[0].ToString());
            PerformSimpleControlScheme(info, horizontal, vertical);
            break;
        }

        float timePassed = info.hitTime - Time.timeSinceLevelLoad;

        if (timePassed >= recalculateHitTime)
        {
            RaycastHit hitinfo;
            Physics.Raycast(this.gameObject.transform.position, hit.surfaceNormal * -10f, out hitinfo);
            if (hitinfo.collider != null)
            {
                hit.hitPoint      = hitinfo.point;
                hit.hitTime       = Time.timeSinceLevelLoad;
                hit.surfaceNormal = hitinfo.normal;
            }
        }

        /*
         * if (runInEditMode)
         * {
         *  Vector3 direction = OriginalDirection(hit.surfaceNormal, horizontal, vertical);
         *  Debug.DrawRay(hit.hitPoint, direction * 10f);
         * }*/
    }
Ejemplo n.º 3
0
    private void FireEvent(ContactPointInfo info, float horizontal, float vertical)
    {
        if (airing)
        {
            return;
        }
        float timeAllowed = 1.2f;
        float timePassed  = info.hitTime - Time.timeSinceLevelLoad;
        float x           = 1.0f - Mathf.Sqrt(Mathf.Clamp01(timePassed / timeAllowed));
        float forceAmount = 800f;

        forceAmount += x * forceAmount;
        Vector3 direction = Direction(hit.surfaceNormal, horizontal, vertical);

        if (timePassed < 3f)
        {
            rb.AddForce(direction * forceAmount);
        }
        else
        {
            RaycastHit hitinfo;
            Physics.Raycast(this.gameObject.transform.position, hit.surfaceNormal * -10f, out hitinfo);
            if (hitinfo.collider != null)
            {
                hit.hitPoint      = hitinfo.point;
                hit.hitTime       = Time.timeSinceLevelLoad;
                hit.surfaceNormal = hitinfo.normal;
            }
        }


        bool debug = true;

        if (debug)
        {
            Debug.DrawRay(hit.hitPoint, direction * 10f);
        }
    }
Ejemplo n.º 4
0
        public void evaluateJointTargets()
        {
            ReducedCharacterState poseRS = new ReducedCharacterState(desiredPose);

            //d and v are specified in the rotation (heading) invariant coordinate frame
            updateDAndV();

            //there are two stages here. First we will compute the pose (i.e. relative orientations), using the joint trajectories for the current state
            //and then we will compute the PD torques that are needed to drive the links towards their orientations - here the special case of the
            //swing and stance hips will need to be considered

            //always start from a neutral desired pose, and build from there...
            root.setExternalForce(Vector3.zero);
            root.setExternalTorque(Vector3.zero);
            CWJoint j;

            for (int i = 0; i < jointCount; i++)
            {
                j = character.getJoint(i);
                j.getChild().setExternalForce(Vector3.zero);
                j.getChild().setExternalTorque(Vector3.zero);
                poseRS.setJointRelativeOrientation(Quaternion.identity, i);
                poseRS.setJointRelativeAngVelocity(Vector3.zero, i);
            }

            float phiToUse = phi;

            //make sure that we only evaluate trajectories for phi values between 0 and 1
            if (phiToUse > 1)
            {
                phiToUse = 1;
            }

            Vector3 force  = Vector3.zero;
            Vector3 torque = Vector3.zero;

            // First compute external forces
            for (int i = 0; i < currentState.getExternalForceCount(); i++)
            {
                ExternalForce ef  = currentState.getExternalForce(i);
                CWRigidBody   arb = character.getArticulatedRigidBody(ef.getARBIndex(stance));

                force  = Vector3.zero;
                force += character.getLocalFrontAxis() * ef.forceX.evaluate_catmull_rom(phiToUse);
                force += character.getLocalUpAxis() * ef.forceY.evaluate_catmull_rom(phiToUse);
                force += character.getLocalLeftAxis() * ef.forceZ.evaluate_catmull_rom(phiToUse);
                force  = characterFrame * force;
                arb.addExternalForce(force);

                torque  = Vector3.zero;
                torque += character.getLocalFrontAxis() * ef.torqueX.evaluate_catmull_rom(phiToUse);
                torque += character.getLocalUpAxis() * ef.torqueY.evaluate_catmull_rom(phiToUse);
                torque += character.getLocalLeftAxis() * ef.torqueZ.evaluate_catmull_rom(phiToUse);
                torque  = characterFrame * torque;
                arb.addExternalTorque(torque);
            }
            //Debug.Log(Random.value + "ffffffffffff  "+curState.getTrajectoryCount());
            for (int i = 0; i < currentState.getTrajectoryCount(); i++)
            {
                Trajectory tra = currentState.getTrajectory(i);
                //now we have the desired rotation angle and axis, so we need to see which joint this is intended for
                int jIndex = tra.getJointIndex(stance, isLeftReverseStance);
                //Debug.Log(Random.value + "00000000000  "+(curState.sTraj[i] as Trajectory).getJointName());
                j = character.getJoint(jIndex);

                //get the desired joint orientation to track - include the feedback if necessary/applicable
                Vector3 d0 = new Vector3();
                Vector3 v0 = new Vector3();
                computeD0(phiToUse, ref d0);
                computeV0(phiToUse, ref v0);

                //if the index is -1, it must mean it's the root's trajectory. Otherwise we should give an error
                if (jIndex == -1)
                {
                    qRootD = tra.evaluateTrajectory(this, j, stance, phiToUse, d - d0, v - v0);
                }
                else
                {
                    Quaternion newOrientation = tra.evaluateTrajectory(this, j, stance, phiToUse, d - d0, v - v0);
                    j.setRelToRootFrame(tra.relToCharFrame);
                    poseRS.setJointRelativeOrientation(newOrientation, jIndex);
                }

                if (tra.hitFeedback != null)
                {
                    CWRigidBody arb = character.getArticulatedRigidBody(tra.hitFeedback.hitARBIndex);
                    if (phiToUse > tra.hitFeedback.minTime && arb.contactPoints.Count > 0)
                    {
                        ContactPointInfo cp = (ContactPointInfo)arb.contactPoints[0];
                        onHitOtherSBCharacter(tra.hitFeedback, cp);
                    }
                }
            }
        }
Ejemplo n.º 5
0
 override protected void ResponseHitOthersFeedback(HitFeedback feedback, ContactPointInfo cp)
 {
     base.ResponseHitOthersFeedback(feedback, cp);
     if (!feedback.isHit)
     {
         /*
          * if (cp.collider2.tag.Contains ("enemyTrunk")) {
          *      //if(cp.collider2.tag == "enemyTrunk"){
          *      EnemyBip enemy = ((cp.collider2.GetComponent ("CWRigidBody") as CWRigidBody).getAFParent () as Character).ownerObject.GetComponent ("EnemyBip") as EnemyBip;
          *
          *      HitFeedback hit = feedback.copy ();
          *      hit.feedbackARB = cp.collider2.GetComponent ("CWRigidBody") as CWRigidBody;
          *      if (hit.feedbackARB.name == "head") {
          *              hit.bodySpringKp = 30;
          *              hit.bodySpringKd = 5;
          *              hit.force /= 1.5f;
          *      }
          *      Vector3 f = Vector3.zero;
          *      f += character.getLocalFrontAxis () * hit.force.x;
          *      f += character.getLocalUpAxis () * hit.force.y;
          *      f += character.getLocalLeftAxis () * hit.force.z;
          *      f = controller.getCharacterFrame () * f;
          *
          *      float levelDiff = GameAttribute.gameAttribute.loadPlayerLevel () - enemy.level;
          *      enemy.addLife (-1 * Mathf.Clamp (hit.power + levelDiff, 1, 100));
          *      hit.localPos = hit.feedbackARB.getLocalCoordinatesPoint (cp.cp);
          *      enemy.startHurt (hit);
          *      cp.collider2.attachedRigidbody.AddForceAtPosition (f, cp.cp, ForceMode.Impulse);
          *      //enemy.pelvis.GetComponent<Rigidbody> ().AddForce (0.5f*f, ForceMode.Impulse);
          *      RFGameManager.instance.addPunch (hit.feedbackARB, cp.cp);
          *
          *      if (weapon == null) {
          *              if (cp.collider1.gameObject == lLowerArm || cp.collider1.gameObject == lLowerLeg) {
          *                      lHandSoundSource.clip = bipedalSounds [Random.Range (2, 10)];
          *                      lHandSoundSource.Play ();
          *              } else if (cp.collider1.gameObject == rLowerArm || cp.collider1.gameObject == rLowerLeg) {
          *                      rHandSoundSource.clip = bipedalSounds [Random.Range (2, 10)];
          *                      rHandSoundSource.Play ();
          *              }
          *      } else {
          *              weapon.playAttackSounds ();
          *              weapon.reduceWeaponWastageRate (2);
          *      }
          *
          *      RFGameManager.instance.addExperience (2 * enemy.level + GameAttribute.gameAttribute.loadPlayerLevel () + 5);
          *
          *      if (enemy.getIsStanding() && RFGameManager.instance.getGameState () == RFGameState.idle) {
          *              RFGameManager.instance.gameStartFighting ();
          *              enemy.resetResist ();
          *              enemy.setLookState (HeadLookState.none, null, Vector3.zero);
          *              enemy.setHandTouchState (HandTouchState.none, null, Vector3.zero, HandTouchMode.doubleHand);
          *      }
          *
          *      //gameManager.createBloodSplash(cp.collider2.gameObject, cp.cp);
          * } else {
          *      if (weapon == null) {
          *      } else {
          *              weapon.playAttackSounds (false);
          *              weapon.reduceWeaponWastageRate (1);
          *      }
          * }*/
         feedback.isHit = true;
     }
 }
Ejemplo n.º 6
0
    override protected void ResponseHitLimbsFeedback(HitFeedback feedback, ContactPointInfo cp)
    {
        base.ResponseHitLimbsFeedback(feedback, cp);

        float volume = 0.03f * feedback.force.magnitude;

        if (feedback.feedbackARB == controller.getLFoot())
        {
            if (cp.collider2.tag.Contains("carpet"))
            {
                lFootSoundSource.clip   = bipedalSounds[0];
                lFootSoundSource.pitch  = 1;
                lFootSoundSource.volume = volume;
                lFootSoundSource.Play();
            }
            else if (cp.collider2.tag.Contains("wood"))
            {
                lFootSoundSource.clip   = bipedalSounds[1];
                lFootSoundSource.pitch  = 1;
                lFootSoundSource.volume = volume;
                lFootSoundSource.Play();
            }
            else if (cp.collider2.tag.Contains("terrain"))
            {
                lFootSoundSource.clip   = bipedalSounds[20];
                lFootSoundSource.pitch  = 0.6f;
                lFootSoundSource.volume = volume;
                lFootSoundSource.Play();
            }

            /*if (lShoes != null && rShoes != null) {
             *      lShoes.reduceShoesWastageRate (0.0025f * feedback.force.magnitude);
             *      rShoes.reduceShoesWastageRate (0.0025f * feedback.force.magnitude);
             * }*/
        }
        else if (feedback.feedbackARB == controller.getRFoot())
        {
            if (cp.collider2.tag.Contains("carpet"))
            {
                rFootSoundSource.clip   = bipedalSounds[0];
                lFootSoundSource.pitch  = 1;
                rFootSoundSource.volume = volume;
                rFootSoundSource.Play();
            }
            else if (cp.collider2.tag.Contains("wood"))
            {
                rFootSoundSource.clip   = bipedalSounds[1];
                lFootSoundSource.pitch  = 1;
                rFootSoundSource.volume = volume;
                rFootSoundSource.Play();
            }
            else if (cp.collider2.tag.Contains("terrain"))
            {
                lFootSoundSource.clip   = bipedalSounds[20];
                lFootSoundSource.pitch  = 0.6f;
                lFootSoundSource.volume = volume;
                lFootSoundSource.Play();
            }

            /*if (lShoes != null && rShoes != null) {
             *      lShoes.reduceShoesWastageRate (0.0025f * feedback.force.magnitude);
             *      rShoes.reduceShoesWastageRate (0.0025f * feedback.force.magnitude);
             * }*/
        }
    }