private float CalculateDamage(float currentVelocity, float targetVelocity, TopmanStats targetHealth)
    {
        // Calculate damage as (our speed + attack) - (target's speed + defense).
        float damage = ((currentVelocity * m_AttackMod) + m_BaseAttack) - ((targetVelocity * targetHealth.m_DefenseMod) + targetHealth.m_BaseDefense);

        // Make sure that the minimum damage is always 0.
        damage = Mathf.Max(0f, damage);

        return(damage);
    }
    private void OnCollisionEnter(Collision col)
    {
        // Get object collided with's health
        TopmanStats targetHealth = col.gameObject.GetComponent <TopmanStats>();

        float damage = 0f;

        if (targetHealth != null)
        {
            Rigidbody targetRigidbody = col.rigidbody;

            damage = CalculateDamage(m_LastVelocity, targetHealth.m_LastVelocity, targetHealth);

            //string s = m_PlayerNumber.ToString() + " " + damage.ToString() + " " + m_Rigidbody.velocity.magnitude.ToString();
            //print (s);

            targetHealth.TakeDamage(damage, 0.1f);


            // Visual and sound effects depend on the strength of the hit
            if ((m_LastVelocity > targetHealth.m_LastVelocity) && (damage < 35) && ((targetHealth.m_CurrentHealth - damage) > 0)) // light hit
            {
                m_LightClashAudio.Play();

                m_LightClashParticles.transform.position = col.transform.position;
                m_LightClashParticles.gameObject.SetActive(true);

                m_LightClashParticles.Play();
            }
            else if ((m_LastVelocity > targetHealth.m_LastVelocity) && (damage >= 35) && ((targetHealth.m_CurrentHealth - damage) > 0)) // heavy hit
            {
                m_HeavyClashAudio.Play();

                m_HeavyClashParticles.transform.position = col.transform.position;
                m_HeavyClashParticles.gameObject.SetActive(true);

                m_HeavyClashParticles.Play();
            }
            // Reset state to neutral if player collides with ANY object while stunned or in the middle of a rush
            else if (playerController.currentState == TopmanPlayerController.StateMachine.STUN || playerController.currentState == TopmanPlayerController.StateMachine.RUSH)
            {
                ResetState();
            }
        }
    }
Example #3
0
    private void OnTriggerEnter(Collider other)
    {
        // Find all targets in an area within hitbox and damage them.
        Rigidbody targetRigidbody = other.GetComponent <Rigidbody>();

        if (!targetRigidbody)
        {
            return;
        }

        TopmanStats targetHealth = targetRigidbody.GetComponent <TopmanStats>();

        if (!targetHealth)
        {
            return;
        }

        float damage = targetHealth.m_StartingHealth;

        targetHealth.TakeDamage(damage);
    }
    private void OnTriggerEnter(Collider other)
    {
        // Find all targets in an area within hitbox and damage them.
        Collider[] colliders = Physics.OverlapSphere(transform.position, transform.localScale.x / 2, m_TankMask);

        switch (currentType)
        {
        case HitboxType.STUN:
            break;

        case HitboxType.BARRIER:
            for (int i = 0; i < colliders.Length; i++)
            {
                Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>();

                if (!targetRigidbody || targetRigidbody == m_OwnerRigidbody)
                {
                    continue;
                }

                TopmanPlayerController targetPlayerController = colliders[i].GetComponent <TopmanPlayerController>();

                if (!targetPlayerController)
                {
                    continue;
                }

                if (targetPlayerController.currentState == TopmanPlayerController.StateMachine.DIVE)
                {
                    continue;
                }

                targetRigidbody.velocity = new Vector3(0f, 0f, 0f);

                targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius);

                TopmanStats targetHealth = targetRigidbody.GetComponent <TopmanStats>();

                if (!targetHealth)
                {
                    continue;
                }

                float damage = m_MaxDamage;

                targetHealth.TakeDamage(damage, m_HitStun);
            }
            break;

        case HitboxType.DIVE:
            for (int i = 0; i < colliders.Length; i++)
            {
                Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>();

                if (!targetRigidbody || targetRigidbody == m_OwnerRigidbody)
                {
                    continue;
                }

                TopmanPlayerController targetPlayerController = colliders[i].GetComponent <TopmanPlayerController>();

                if (!targetPlayerController)
                {
                    continue;
                }

                if (targetPlayerController.currentState == TopmanPlayerController.StateMachine.RUSH)
                {
                    continue;
                }

                targetRigidbody.velocity = new Vector3(0f, 0f, 0f);

                targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius);

                TopmanStats targetHealth = targetRigidbody.GetComponent <TopmanStats>();

                if (!targetHealth)
                {
                    continue;
                }

                float damage = CalculateDamage(targetRigidbody.position);

                targetHealth.TakeDamage(damage, m_HitStun);
            }
            gameObject.GetComponent <SphereCollider>().enabled = false;
            Destroy(gameObject);
            break;
        }
    }