Exemplo n.º 1
0
    private void OnCollisionEnter(Collision other)
    {
        int layer = other.gameObject.layer;

        if (other.gameObject.layer == LayerMask.NameToLayer("Ground"))
        {
            CameraShaker.Instance.ShakeOnce(5.5f * GameState.Instance.cameraShake, 1.2f, 0.2f, 0.3f);
            if (wallRunning && other.contacts[0].normal.y == -1f)
            {
                MonoBehaviour.print("ROOF");
                return;
            }
            wallNormalVector = other.contacts[0].normal;
            MonoBehaviour.print("nv: " + wallNormalVector);
            AudioManager.Instance.PlayLanding();
            if (Math.Abs(wallNormalVector.y) < 0.1f)
            {
                StartWallRun();
            }
            airborne = false;
        }
        if (layer != LayerMask.NameToLayer("Enemy") || (grounded && !crouching) || rb.velocity.magnitude < 3f)
        {
            return;
        }
        Enemy enemy = (Enemy)other.transform.root.GetComponent(typeof(Enemy));

        if ((bool)enemy && !enemy.IsDead())
        {
            UnityEngine.Object.Instantiate(PrefabManager.Instance.enemyHitAudio, other.contacts[0].point, Quaternion.identity);
            RagdollController ragdollController = (RagdollController)other.transform.root.GetComponent(typeof(RagdollController));
            if (grounded && crouching)
            {
                ragdollController.MakeRagdoll(rb.velocity * 1.2f * 34f);
            }
            else
            {
                ragdollController.MakeRagdoll(rb.velocity.normalized * 250f);
            }
            rb.AddForce(rb.velocity.normalized * 2f, ForceMode.Impulse);
            enemy.DropGun(rb.velocity.normalized * 2f);
        }
    }
Exemplo n.º 2
0
    private void KillEnemy(Collision other)
    {
        if ((grounded && !crouching) || rb.velocity.magnitude < 3f)
        {
            return;
        }
        Enemy enemy = (Enemy)other.transform.root.GetComponent(typeof(Enemy));

        if ((bool)enemy && !enemy.IsDead())
        {
            UnityEngine.Object.Instantiate(PrefabManager.Instance.enemyHitAudio, other.contacts[0].point, Quaternion.identity);
            RagdollController ragdollController = (RagdollController)other.transform.root.GetComponent(typeof(RagdollController));
            if (grounded && crouching)
            {
                ragdollController.MakeRagdoll(rb.velocity * 1.2f * 34f);
            }
            else
            {
                ragdollController.MakeRagdoll(rb.velocity.normalized * 250f);
            }
            rb.AddForce(rb.velocity.normalized * 2f, ForceMode.Impulse);
            enemy.DropGun(rb.velocity.normalized * 2f);
        }
    }
Exemplo n.º 3
0
    private void OnTriggerEnter(Collider other)
    {
        int     layer      = other.gameObject.layer;
        Vector3 normalized = (other.transform.position - base.transform.position).normalized;
        float   num        = Vector3.Distance(other.transform.position, base.transform.position);

        if (other.gameObject.CompareTag("Enemy"))
        {
            if (other.gameObject.name != "Torso")
            {
                return;
            }
            RagdollController ragdollController = (RagdollController)other.transform.root.GetComponent(typeof(RagdollController));
            if ((bool)ragdollController && !ragdollController.IsRagdoll())
            {
                ragdollController.MakeRagdoll(normalized * 1100f);
                if (player)
                {
                    PlayerMovement.Instance.Slowmo(0.35f, 0.5f);
                }
                Enemy enemy = (Enemy)other.transform.root.GetComponent(typeof(Enemy));
                if ((bool)enemy)
                {
                    enemy.DropGun(Vector3.up);
                }
            }
            return;
        }
        Rigidbody component = other.gameObject.GetComponent <Rigidbody>();

        if ((bool)component)
        {
            if (num < 5f)
            {
                num = 5f;
            }
            component.AddForce(normalized * 450f / num, ForceMode.Impulse);
            component.AddTorque(new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f)) * 10f);
            if (layer == LayerMask.NameToLayer("Player"))
            {
                ((PlayerMovement)other.transform.root.GetComponent(typeof(PlayerMovement))).Explode();
            }
        }
    }