Beispiel #1
0
 private void Awake()
 {
     rb        = GetComponent <Rigidbody>();
     oppLayer  = gameObject.layer == 9 ? 10 : 9;
     collision = new OpponentCollision()
     {
         bodyPartA = GetComponent <BodyPart>()
     };
 }
Beispiel #2
0
 private bool IsPausablePunch(OpponentCollision collision, out float force)
 {
     force = collision.velocity.magnitude;
     // TODO latency / hand position issue.
     return(timeSincePauseStart > duration * 2f &&
            force >= minForce &&
            collision.IsUpperBodyHit() &&
            (collision.bodyPartA.transform.position -
             collision.bodyPartB.transform.position).magnitude < 0.4f);
 }
Beispiel #3
0
 private void OnCollision(OpponentCollision collision)
 {
     if (collision.IsPunch() && !collision.OpponentBlocksPunch())
     {
         float force = collision.velocity.magnitude;
         CrntForce = force;
         if (force >= MinForce)
         {
             AccumForce += force;
             OnValidPunch?.Invoke(collision); // demo
             // Debug.Log($"Punch {name}: {collision.bodyPartA.name} -> {collision.bodyPartB.name} | {force}");
         }
     }
 }
Beispiel #4
0
        private void Pause(OpponentCollision collision)
        {
            tmpLookTarget = collision.bodyPartA.transform.position;

            foreach (var rb in rigidbodies)
            {
                rb.Sleep();
            }
            foreach (var dr in decisionRequesters)
            {
                dr.IsPaused = true;
            }

            isPaused       = true;
            pauseStartTime = Time.time;
            Invoke("EndPause", duration);
        }
Beispiel #5
0
        private void OnValidPunchA(OpponentCollision collision)
        {
            if (IsPausablePunch(collision, out float force))
            {
                textPunchA.text    = $"FORCE {Round(force)}";
                textPunchA.enabled = true;
                if (collision.bodyPartA.Side == BodyPartSide.Left)
                {
                    leftHandA.enabled = true;
                }
                else
                {
                    rightHandA.enabled = true;
                }

                Pause(collision);
            }
        }