Beispiel #1
0
    private void OnCollisionStay(Collision other)
    {
        //Debug.Log("From "+gameObject.name+" ->Collider: "+ other.contacts[0].thisCollider.name + "collided with " + other.contacts[0].otherCollider);
        GameObject colliderEnfant = other.contacts[0].thisCollider.gameObject;
        GameObject autreCollider  = other.contacts[0].otherCollider.gameObject;

        if (autreCollider.gameObject.tag == "weaponCollider")
        {
            Destroyable _destroyableTemp = other.contacts[0].thisCollider.gameObject.GetComponent <Destroyable>();
            if (_destroyableTemp != null)
            {
                Instantiate(_impactParticle, other.contacts[0].point, transform.rotation);
                Weapon compWeapon           = autreCollider.GetComponent <Weapon>();
                int    probabiliteKnockBack = Mathf.RoundToInt(UnityEngine.Random.Range(0, 100));
                if (probabiliteKnockBack < 4)
                {
                    Vector3 direction = calculDirectionKnockback(other.contacts[0].point, transform.position);
                    foreach (Moteur roue in _rouesmoteur)
                    {
                        roue.SetVitesse = 0;
                    }
                    playVariatedSound(impactKB);
                    _rbody.AddForce(direction * compWeapon.KnockBack, ForceMode.Impulse);
                }

                playVariatedSound(smallHit, compWeapon.ValDommage / 10);
                _destroyableTemp.endommager(compWeapon.ValDommage);
            }
        }
        else if (autreCollider.gameObject.tag == "walls")
        {
            Vector3 direction = calculDirectionKnockback(other.contacts[0].point, transform.position);
            _rbody.AddForce(direction * 3, ForceMode.Impulse);
        }
    }