ProjectStorms.ShipPartDestroy.EvaluatePlayerCollision C# (CSharp) Méthode

EvaluatePlayerCollision() private méthode

Evaluates the collision with the input collider.
private EvaluatePlayerCollision ( Collider a_otherCol, Vector3 a_velDiff, float a_colVelSqr ) : void
a_otherCol UnityEngine.Collider
a_velDiff UnityEngine.Vector3 Relative collision velocity.
a_colVelSqr float Squared relative collision velocity magnitude.
Résultat void
        private void EvaluatePlayerCollision(Collider a_otherCol, Vector3 a_velDiff, float a_colVelSqr)
        {
            // Get scripts
            AirshipControlBehaviour ship = a_otherCol.GetComponentInParent<AirshipControlBehaviour>();
            if (ship != null)
            {
                PassengerTray otherTray = ship.gameObject.GetComponentInChildren<PassengerTray>();

                if (otherTray != null)
                {
                    // Establish collision direction
                    Transform otherTrans = a_otherCol.transform;
                    float forwardDot = Vector3.Dot(m_trans.forward, otherTrans.forward);
                    float rightDot = Vector3.Dot(m_trans.right, otherTrans.right);

                    // Get positions
                    Vector3 myPos = m_trans.position;
                    Vector3 otherPos = otherTrans.position;
                    Vector3 offset = otherPos - myPos;

                    Rigidbody rbOther = a_otherCol.GetComponent<Rigidbody>();

                    if (rbOther == null)
                    {
                        rbOther = a_otherCol.GetComponentInParent<Rigidbody>();
                    }

                    // For evaluating whether the collision is from below/above
                    float upDot = Vector3.Dot(offset.normalized, otherTrans.up);

                    /*Debug.Log("Front dot: " + Mathf.Abs(forwardDot) +
                        ", right dot: " + Mathf.Abs(rightDot) +
                        ", up dot: " + Mathf.Abs(upDot) +
                        ", threshold: " + colDirThreshold);*/

                    bool powerDownOther = false;
                    bool powerDownMe = false;

                    if (upDot >= 1 - colDirThreshold &&
                        offset.y > 0)
                    {
                        // Above - My ship onto them from above

                        // Make them lose passengers
                        //Debug.Log("Collision - From Above!");
                        powerDownOther = true;
                    }
                    else if (upDot <= -1 + colDirThreshold &&
                        offset.y < 0)
                    {
                        // Below - My ship onto them from below

                        // Make them lose passengers
                        //Debug.Log("Collision - From Below!");
                        powerDownOther = true;
                    }
                    else if (Mathf.Abs(forwardDot) <= colDirThreshold)
                    {
                        // T-Bone - My front into their side

                        // Make them lose passengers
                        //Debug.Log("Collision - From T-Bone!");
                        powerDownOther = true;
                    }
                    else if (forwardDot <= -1 + colDirThreshold)
                    {
                        // Head on - My front into their front

                        // Make both lose passengers
                        //Debug.Log("Collision - From Head On!");
                        powerDownMe = true;
                        powerDownOther = true;
                    }
                    else if (forwardDot >= 1 - colDirThreshold)
                    {
                        // Behind - My front into their back

                        // Make them lose passengers
                        //Debug.Log("Collision - From Behind!");
                        powerDownOther = true;
                    }
                    else if (Mathf.Abs(rightDot) >= 1 - colDirThreshold)
                    {
                        // Horizontal/Side by side - My ship gently bumping them

                        // Make nobody lose passengers
                        //Debug.Log("Collision - Horiztonal bump!");
                    }
                    else if (a_colVelSqr >= m_bumpVelSqr)
                    {
                        // Colliding above rumble threshold from random angle, both lose passengers
                        InputManager.SetControllerVibrate(gameObject.tag, bumpRumbleStr, bumpRumbleStr, bumpRumbleDurr, true);

                        // Turn off the passenger tray for a bit
                        powerDownMe = true;
                        powerDownOther = true;
                    }

                    if (powerDownMe)
                    {
                        m_shipTray.PowerDownTray();

                        // Launch passengers with relative velocity
                        Rigidbody rbTemp = null;
                        List<GameObject> contents = m_shipTray.trayContents;
                        foreach (GameObject passenger in contents)
                        {
                            rbTemp = passenger.GetComponent<Rigidbody>();
                            if (rbTemp != null)
                            {
                                rbTemp.AddForce(rbOther.velocity, ForceMode.VelocityChange);
                            }
                        }
                    }
                    if (powerDownOther)
                    {
                        m_shipTray.PowerDownTray();

                        // Launch passengers with relative velocity
                        Rigidbody rbTemp = null;
                        List<GameObject> contents = otherTray.trayContents;
                        foreach (GameObject passenger in contents)
                        {
                            rbTemp = passenger.GetComponent<Rigidbody>();
                            if (rbTemp != null)
                            {
                                rbTemp.AddForce(m_rb.velocity, ForceMode.VelocityChange);
                            }
                        }
                    }
                }
            }
        }