Beispiel #1
0
    public void SetRammingKnockback(Collision collision, ICollisionReceiver hitCollisionReceiver)
    {
        #region Calculates Redirection and Knockback
        Vector3 knockbackVector   = relatedShip.GetShipVelocity.normalized;
        Vector3 redirectionVector = hitCollisionReceiver.GetMovementDirection();

        Vector3 hitObjectDirection = Quaternion.Euler(-collision.transform.rotation.eulerAngles) * hitCollisionReceiver.GetMovementDirection();

        Vector3 hitNormal   = new Vector3();
        Vector3 hitPosition = new Vector3();
        Vector3 worldHitPosition;
        int     counter = 0;

        foreach (ContactPoint contact in collision.contacts)
        {
            hitNormal   += contact.normal;
            hitPosition += contact.point;
            counter++;
        }

        #region V1
        Vector3 hitObjectCenter = collision.collider.bounds.center;

        hitNormal /= counter;
        hitNormal  = Quaternion.Euler(-collision.transform.rotation.eulerAngles) * hitNormal;

        hitPosition     /= counter;
        worldHitPosition = hitPosition;
        hitPosition      = Quaternion.Euler(-collision.transform.rotation.eulerAngles) * (hitPosition - hitObjectCenter);

        float semiLenght = collision.collider.bounds.extents.z;
        float semiWidht  = collision.collider.bounds.extents.x;

        if (Mathf.Abs(Vector3.Dot(hitNormal, hitObjectDirection)) < 0.5f)
        {
            //latéral
            if (hitPosition.x > 0)
            {
                //par la droite
                if (hitPosition.z > 0)
                {
                    //à l'avant
                    if (Vector3.Dot(GetMovementDirection(), hitCollisionReceiver.GetMovementDirection()) > -0.45f)
                    {
                        knockbackVector   = -hitCollisionReceiver.GetMovementDirection();
                        redirectionVector = ((-hitCollisionReceiver.GetMovementDirection().normalized + hitCollisionReceiver.GetMovementDirection().GetLeftOrthogonalVectorXZ().normalized) / 2).normalized;
                        //Debug.Log("pas exception");
                    }
                    else if (Vector3.Dot(GetMovementDirection(), hitCollisionReceiver.GetMovementDirection()) < 0f)
                    {
                        knockbackVector   = hitCollisionReceiver.GetMovementDirection().GetLeftOrthogonalVectorXZ();
                        redirectionVector = ((hitCollisionReceiver.GetMovementDirection().normalized + hitCollisionReceiver.GetMovementDirection().GetLeftOrthogonalVectorXZ().normalized) / 2).normalized;
                        //Debug.Log("exception");
                    }
                    //Debug.Log("latéral avant droit");
                }
                else
                {
                    //à l'arrière
                    if (Vector3.Dot(GetMovementDirection(), hitCollisionReceiver.GetMovementDirection()) < 0.75f)
                    {
                        knockbackVector   = hitCollisionReceiver.GetMovementDirection();
                        redirectionVector = ((hitCollisionReceiver.GetMovementDirection().normalized + hitCollisionReceiver.GetMovementDirection().GetRightOrthogonalVectorXZ().normalized) / 2).normalized;
                        //Debug.Log("pas exception");
                    }
                    else
                    {
                        knockbackVector   = hitCollisionReceiver.GetMovementDirection().GetLeftOrthogonalVectorXZ();
                        redirectionVector = ((hitCollisionReceiver.GetMovementDirection().normalized + hitCollisionReceiver.GetMovementDirection().GetLeftOrthogonalVectorXZ().normalized) / 2).normalized;
                        //Debug.Log("exception");
                    }
                    //Debug.Log("latéral arrière droit");
                }
            }
            else
            {
                //par la gauche
                if (hitPosition.z > 0)
                {
                    //à l'avant
                    if (Vector3.Dot(GetMovementDirection(), hitCollisionReceiver.GetMovementDirection()) > -0.45f)
                    {
                        knockbackVector   = -hitCollisionReceiver.GetMovementDirection();
                        redirectionVector = ((-hitCollisionReceiver.GetMovementDirection().normalized + hitCollisionReceiver.GetMovementDirection().GetRightOrthogonalVectorXZ().normalized) / 2).normalized;
                        //Debug.Log("pas exception");
                    }
                    else
                    {
                        knockbackVector   = hitCollisionReceiver.GetMovementDirection().GetRightOrthogonalVectorXZ();
                        redirectionVector = ((hitCollisionReceiver.GetMovementDirection().normalized + hitCollisionReceiver.GetMovementDirection().GetRightOrthogonalVectorXZ().normalized) / 2).normalized;
                        //Debug.Log("exception");
                    }
                    //Debug.Log("latéral avant gauche");
                }
                else
                {
                    //à l'arrière
                    if (Vector3.Dot(GetMovementDirection(), hitCollisionReceiver.GetMovementDirection()) < 0.75f)
                    {
                        knockbackVector   = hitCollisionReceiver.GetMovementDirection();
                        redirectionVector = ((hitCollisionReceiver.GetMovementDirection().normalized + hitCollisionReceiver.GetMovementDirection().GetLeftOrthogonalVectorXZ().normalized) / 2).normalized;
                        //Debug.Log("pas exception");
                    }
                    else
                    {
                        knockbackVector   = hitCollisionReceiver.GetMovementDirection().GetRightOrthogonalVectorXZ();
                        redirectionVector = ((hitCollisionReceiver.GetMovementDirection().normalized + hitCollisionReceiver.GetMovementDirection().GetRightOrthogonalVectorXZ().normalized) / 2).normalized;
                        //Debug.Log("exception");
                    }
                    //Debug.Log("latéral arrière gauche");
                }
            }
        }
        else
        {
            //avant ou arrière
            if (hitPosition.x > 0)
            {
                // sur la droite
                //knockbackVector = ((hitCollisionReceiver.GetMovementDirection().normalized + hitCollisionReceiver.GetMovementDirection().GetLeftOrthogonalVectorXZ().normalized) / 2).normalized;
                knockbackVector   = hitCollisionReceiver.GetMovementDirection().GetLeftOrthogonalVectorXZ().normalized;
                redirectionVector = ((hitCollisionReceiver.GetMovementDirection().normalized + hitCollisionReceiver.GetMovementDirection().GetLeftOrthogonalVectorXZ().normalized) / 2).normalized;
                //Debug.Log("frontal droite");
            }
            else
            {
                // sur la gauche
                //knockbackVector = ((hitCollisionReceiver.GetMovementDirection().normalized + hitCollisionReceiver.GetMovementDirection().GetRightOrthogonalVectorXZ().normalized) / 2).normalized;
                knockbackVector   = hitCollisionReceiver.GetMovementDirection().GetRightOrthogonalVectorXZ().normalized;
                redirectionVector = ((hitCollisionReceiver.GetMovementDirection().normalized + hitCollisionReceiver.GetMovementDirection().GetRightOrthogonalVectorXZ().normalized) / 2).normalized;
                //Debug.Log("frontal gauche");
            }
        }
        #endregion

        #endregion

        DealKnockback(hitCollisionReceiver, relatedShip.ShipMvt.GetCurrentRammingParameters.GetInflictedKnockbackParameters, knockbackVector, redirectionVector);

        ReceiveKnockback(this, relatedShip.ShipMvt.GetCurrentRammingParameters.GetSustainedKnockbackParametersOnImpact, -relatedShip.GetShipVelocity.normalized, relatedShip.GetShipVelocity.normalized);

        #region Feedback
        if (waitBeforeRammingFeedback)
        {
            return;
        }

        if ((relatedShip as EnemyShip != null && collision.gameObject.GetComponent <PlayerShip>() != null) /* || (relatedShip as PlayerShip != null && collision.gameObject.GetComponent<EnemyShip>() != null)*/)
        {
            GameManager.gameManager.SlwMoManager.SetSlowMo(relatedShip.ShipMvt.GetCurrentRammingParameters.GetSlowMoParameters);
        }

        GameManager.gameManager.ScrshkManager.StartScreenshake(relatedShip.ShipMvt.GetCurrentRammingParameters.GetScreenshakeParameters);

        FeedbackObject woodProjection = GameManager.gameManager.PoolManager.GetFeedbackObject(FeedbackObjectPoolTag.WoodDestruction, PoolInteractionType.GetFromPool);
        if (woodProjection != null)
        {
            woodProjection.transform.position = worldHitPosition;
            woodProjection.StartFeedback(2, 0.2f);
        }
        StartCoroutine(WaitBeforeReplayRammingFeedback());
        #endregion
    }
Beispiel #2
0
    private void OnCollisionEnter(Collision collision)
    {
        ShipHitbox hitShipHitbox = collision.gameObject.GetComponent <ShipHitbox>();

        IDamageReceiver damageReceiver = collision.gameObject.GetComponent <IDamageReceiver>();

        if (damageReceiver != null)
        {
            if (hitShipHitbox != null)
            {
                if (!playerHitObstacleOnce)
                {
                    PlayerShip playerShip = hitShipHitbox.GetRelatedShip as PlayerShip;
                    if (playerShip != null)
                    {
                        if (ArenaManager.arenaManager != null)
                        {
                            ArenaManager.arenaManager.ScoreMng.SetPlayerHasHitObstacle();
                            playerHitObstacleOnce = true;
                        }
                    }
                }

                if (!hitShipHitbox.GetRelatedShip.BeingSkewered)
                {
                    bool      enemyDontGetDamaged = false;
                    EnemyShip enemyShip           = hitShipHitbox.GetRelatedShip as EnemyShip;
                    if (enemyShip != null)
                    {
                        if (enemyShip.GetCurrentLifeAmount <= damagesParameters.GetDamageAmount)
                        {
                            enemyDontGetDamaged = true;
                        }
                    }

                    if (!enemyDontGetDamaged)
                    {
                        DealDamage(damageReceiver, damagesParameters);
                    }
                }
                else
                {
                    hitShipHitbox.ReceiveDamage(hitShipHitbox, hitShipHitbox.GetRelatedShip.GetSkeweringParameters.GetDamagesOnImpact, null);

                    if (hitShipHitbox.GetRelatedShip.GetSkeweringParameters != null)
                    {
                        hitShipHitbox.GetRelatedShip.SetStun(hitShipHitbox.GetRelatedShip.GetSkeweringParameters.GetStunOnObstacleDuration);
                    }

                    hitShipHitbox.GetRelatedShip.EndSkewering();
                }
            }
            else
            {
                DealDamage(damageReceiver, damagesParameters);
            }
        }

        ICollisionReceiver collisionReceiver = collision.gameObject.GetComponent <ICollisionReceiver>();

        if (collisionReceiver != null)
        {
            Vector3 normal  = new Vector3();
            float   counter = 0;
            Vector3 pos     = new Vector3();

            foreach (ContactPoint contact in collision.contacts)
            {
                normal -= contact.normal;
                counter++;
                pos += contact.point;
            }

            normal /= counter;
            pos    /= counter;

            normal.y = 0;
            normal.Normalize();

            Vector3 redirection = Vector3.Reflect(collisionReceiver.GetMovementDirection(), normal).normalized;
            redirection.y = 0;
            redirection.Normalize();

            if (hitShipHitbox != null)
            {
                if (hitShipHitbox.GetRelatedShip.BeingSkewered)
                {
                    redirection = Vector3.zero;
                }
            }

            DealKnockback(collisionReceiver, knockbackParameters, normal, redirection);
        }
    }