示例#1
0
 void Awake()
 {
     if (target != null)
     {
         receiver = target.GetComponent <ICollisionReceiver>();
     }
 }
示例#2
0
    private void OnTriggerStay(Collider other)
    {
        IDamageReceiver hitDamageReceiver = other.GetComponent <IDamageReceiver>();

        if (hitDamageReceiver != null)
        {
            DealDamage(hitDamageReceiver, relatedExplosion.CurrentExplParameters.explosionAttackParameters.GetDamagesParameters);
        }

        ICollisionReceiver hitCollisionReceiver = other.GetComponent <ICollisionReceiver>();

        if (hitCollisionReceiver != null)
        {
            Vector3 knockbackDirection = new Vector3();
            knockbackDirection = other.transform.position - transform.position;
            knockbackDirection = new Vector3(knockbackDirection.x, 0, knockbackDirection.z).normalized;

            DealKnockback(hitCollisionReceiver, relatedExplosion.CurrentExplParameters.explosionAttackParameters.GetKnockbackParameters, knockbackDirection, knockbackDirection);
        }
    }
示例#3
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
    }
示例#4
0
    private void OnCollisionStay(Collision collision)
    {
        bool hasRammingPriority = true;

        if (relatedShip.ShipMvt.GetCurrentRammingParameters.IsAttacking)
        {
            ShipHitbox hitShipHitbox = collision.gameObject.GetComponent <ShipHitbox>();
            if (hitShipHitbox != null)
            {
                if (hitShipHitbox.relatedShip.ShipMvt.GetCurrentRammingParameters.IsAttacking)
                {
                    //les deux attaquent, il faut vérifier si l'autre est le joueur
                    if (hitShipHitbox.relatedShip as PlayerShip != null)
                    {
                        hasRammingPriority = false;
                    }
                }
            }
        }
        else
        {
            hasRammingPriority = false;
        }


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

        if (hitCollisionReceiver != null)
        {
            if (hitCollisionReceiver.Recovering())
            {
                return;
            }

            if (relatedShip.ShipMvt.GetCurrentRammingParameters.IsAttacking)
            {
                if (hasRammingPriority)
                {
                    SetRammingKnockback(collision, hitCollisionReceiver);
                }
            }
            else
            {
                ShipHitbox hitShip = collision.gameObject.GetComponent <ShipHitbox>();
                if (hitShip != null)
                {
                    if (OnOtherShipCollision != null)
                    {
                        OnOtherShipCollision(hitShip.relatedShip);
                    }

                    if (!hitShip.relatedShip.ShipMvt.GetCurrentRammingParameters.IsRamming)
                    {
                        Vector3 knockbackDir = hitShip.transform.position - transform.position;
                        knockbackDir.y = 0;
                        knockbackDir.Normalize();

                        DealKnockback(hitCollisionReceiver, shipCollisionKnockbackParameters, knockbackDir, knockbackDir);
                    }

                    if (relatedShip.BeingSkewered)
                    {
                        hitShip.relatedShip.SetStun(relatedShip.GetSkeweringParameters.GetStunOnOtherShipDuration);
                        DealDamage(hitShip, relatedShip.GetSkeweringParameters.GetDamagesOnImpact);

                        relatedShip.SetStun(relatedShip.GetSkeweringParameters.GetStunOnOtherShipDuration);
                        ReceiveDamage(this, relatedShip.GetSkeweringParameters.GetDamagesOnImpact, null);

                        relatedShip.EndSkewering();
                    }
                }
            }
        }

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

        if (hitDamageReceiver != null)
        {
            if (relatedShip.ShipMvt.GetCurrentRammingParameters.IsAttacking)
            {
                if (hasRammingPriority)
                {
                    DealDamage(hitDamageReceiver, relatedShip.ShipMvt.GetCurrentRammingParameters.GetDamagesParameters);
                }

                if (relatedShip as PlayerShip != null)
                {
                    GameManager.gameManager.SlwMoManager.SetSlowMo(relatedShip.ShipMvt.GetCurrentRammingParameters.GetSlowMoParameters);
                }
            }
        }
    }
示例#5
0
 public void DealKnockback(ICollisionReceiver collisionReceiver, KnockbackParameters knockbackParameters, Vector3 knockbackDirection, Vector3 redirection)
 {
     collisionReceiver.ReceiveKnockback(this, knockbackParameters, knockbackDirection, redirection);
 }
示例#6
0
 void Awake()
 {
     receiver = collisionReceiver.GetComponent <ICollisionReceiver>();
 }
示例#7
0
    // Update is called once per frame
    void FixedUpdate()
    {
        const float shell = 0.005f;

        Vector2 targetSpeed  = _moveInput * maxSpeed;
        Vector2 speedDiff    = targetSpeed - Vector2.Scale(_Velocity, new Vector2(1, 0));
        Vector2 acceleration = Vector2.up * LevelSettings.Instance.gravity * gravityModifier * Time.deltaTime;

        if (speedDiff.magnitude != 0.0)
        {
            acceleration += moveAcceleration * speedDiff * Time.deltaTime;

            if (!_grounded)
            {
                acceleration.x = airAccelerationFactor * acceleration.x;
            }
        }

        Vector2 dv = acceleration;

        if (Mathf.Abs(dv.x) > Mathf.Abs(speedDiff.x))
        {
            dv.x = Mathf.Sign(dv.x) * Mathf.Abs(speedDiff.x);
        }

        _Velocity = _Velocity + dv;

        Vector2 framedAcceleration = new Vector2(groundNormal.y, -groundNormal.x) * _Velocity.x * Time.deltaTime;

        _grounded = false;

        int count = _Rigidbody.Cast(Vector2.zero, _filter, _hitBuffer, 0);

        _hitBufferList.Clear();
        for (int i = 0; i < count; ++i)
        {
            _hitBufferList.Add(_hitBuffer[i]);
        }

        collisionCallback(ref _hitBufferList, CollisionStage.Before);

        //do the X movement first
        Vector2 xMove = framedAcceleration;
        float   dist  = framedAcceleration.magnitude;

        if (dist > 0.001f)
        {
            count = _Rigidbody.Cast(xMove.normalized, _filter, _hitBuffer, dist + shell);
            _hitBufferList.Clear();
            for (int i = 0; i < count; ++i)
            {
                _hitBufferList.Add(_hitBuffer[i]);
            }

            if (collisionCallback != null)
            {
                collisionCallback.Invoke(ref _hitBufferList, CollisionStage.XMove);
            }

            for (int i = 0; i < _hitBufferList.Count; ++i)
            {
                RaycastHit2D hit     = _hitBufferList[i];
                Vector2      cntNorm = hit.normal;

                ICollisionReceiver physObj = _hitBufferList[i].collider.GetComponent <ICollisionReceiver>();
                if (physObj != null)
                {
                    physObj.ReceiveContact(this, _hitBufferList[i]);
                }



                if (cntNorm.y > 0.7f)
                {
                    _grounded = true;
                }

                float proj = Vector2.Dot(_Velocity, cntNorm);

                if (proj < 0)
                {
                    _Velocity = _Velocity - proj * cntNorm;
                }

                float modifDist = _hitBufferList[i].distance - shell;
                dist = modifDist < dist ? modifDist : dist;
            }
            _Rigidbody.position = (_Rigidbody.position + xMove.normalized * dist);
        }


        //do the Y movement second
        Vector2 yMove = Vector2.up * _Velocity.y * Time.deltaTime; // new Vector2(0, dp.y);

        dist = yMove.magnitude;                                    //Mathf.Abs(dp.y);
        if (dist > 0.001f)
        {
            count = _Rigidbody.Cast(yMove.normalized, _filter, _hitBuffer, dist + shell);
            _hitBufferList.Clear();
            for (int i = 0; i < count; ++i)
            {
                _hitBufferList.Add(_hitBuffer[i]);
            }

            if (collisionCallback != null)
            {
                collisionCallback.Invoke(ref _hitBufferList, CollisionStage.YMove);
            }

            for (int i = 0; i < _hitBufferList.Count; ++i)
            {
                RaycastHit2D hit     = _hitBufferList[i];
                Vector2      cntNorm = hit.normal;

                ICollisionReceiver physObj = _hitBufferList[i].collider.GetComponent <ICollisionReceiver>();
                if (physObj != null)
                {
                    physObj.ReceiveContact(this, _hitBufferList[i]);
                }

                if (cntNorm.y > 0.7f)
                {
                    groundNormal = cntNorm;
                    _grounded    = true;
                    cntNorm.x    = 0;
                }

                float proj = Vector2.Dot(_Velocity, cntNorm);

                if (proj < 0)
                {
                    _Velocity = _Velocity - proj * cntNorm;
                }

                float modifDist = _hitBufferList[i].distance - shell;
                dist = modifDist < dist ? modifDist : dist;
            }
        }

        _Rigidbody.position = (_Rigidbody.position + yMove.normalized * dist);
    }
示例#8
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);
        }
    }
示例#9
0
 private void Start()
 {
     triggerReceiver = GetComponentInParent <ICollisionReceiver>();
 }