예제 #1
0
    void FireBullet()
    {
        Ray        ray = new Ray(Muzzle.position, Muzzle.forward);
        RaycastHit hit;

        Physics.Raycast(ray, out hit);

        flashLine.positionCount = 2;

        flashLine.SetPosition(0, Muzzle.position);
        flashLine.SetPosition(1, hit.point);
        flashStay         = FlashStayTime;
        flashLine.enabled = true;

        if (hit.collider)
        {
            UnitHealth  hitBody     = hit.collider.gameObject.GetComponent <UnitHealth>();
            HitCollider hitCollider = hit.collider.gameObject.GetComponent <HitCollider>();

            if (!hitBody && hitCollider && hitCollider.ColliderType == HitCollider.Type.Receive)
            {
                hitBody = hitCollider.GetOwner();
            }

            if (hitBody)
            {
                hitBody.Damage(DamagePerBullet);
            }
        }
    }
예제 #2
0
파일: Pitfall.cs 프로젝트: Smcmax/GameJam
    void OnCollisionEnter2D(Collision2D collision)
    {
        collision.collider.gameObject.transform.position = new Vector3(respawnPoint.position.x, respawnPoint.position.y);
        UnitHealth health = collision.collider.GetComponent <UnitHealth>();

        if (health)
        {
            health.Damage(pitDamage);
        }
    }
예제 #3
0
    void OnAttackHit(HitCollider self, HitCollider other)
    {
        if (activeHit)
        {
            if (attackIsHit)
            {
                self.enabled = false;
                return;
            }

            UnitHealth owner = other.GetOwner();

            float angle = Mathf.Abs(Vector3.SignedAngle(owner.transform.forward, (transform.position - owner.transform.position).normalized, Vector3.up));

            // attacks from the back deal triple the damage
            if (angle > 90)
            {
                owner.Damage(100);
            }
            else
            {
                owner.Damage(36);
            }

            if (other.GetOwner().IsDead())
            {
                Transform chest = other.GetOwner().GetComponent <Animator>().GetBoneTransform(HumanBodyBones.Chest);
                Vector3   force = (chest.position - transform.position);
                force.y  = 0;
                force    = force.normalized;
                force.y += 0.8f;
                force    = force.normalized;
                force   *= 200;
                chest.GetComponent <Rigidbody>().AddForce(force, ForceMode.Impulse);
            }

            attackIsHit = true;
        }
    }
예제 #4
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        UnitHealth targetHealth = other.transform.root.GetComponentInChildren <UnitHealth>();

        if (targetHealth != null)
        {
            targetHealth.Damage(damageAmount.Value);
            dealtDamage.Invoke();
            if (targetHealth.Health <= 0)
            {
                destroyedOther.Invoke();
            }
        }
    }
예제 #5
0
    public void OnDamage(Shooter p_damager, DamageType p_type, int p_damage, bool p_bypassDefense, bool p_bypassImmunityWindow)
    {
        if (m_health)
        {
            int finalDamage = p_damage;
            int effective   = p_type.IsEffectiveAgainst(m_type);

            if (!p_bypassDefense)
            {
                finalDamage -= m_stats.GetStatEffect(Stats.DEF);
            }
            if (effective == 1)
            {
                finalDamage = Mathf.CeilToInt(finalDamage * 1.5f);
            }
            else if (effective == -1)
            {
                finalDamage /= 2;
            }

            int resistance = Mathf.FloorToInt(m_modifiers.GetModifier(p_type.m_name + " Resistance"));
            finalDamage -= resistance;

            if (m_feedbackTemplate && (!m_health.IsImmune() || p_bypassImmunityWindow))
            {
                FeedbackGenerator.GenerateFeedback(transform, m_feedbackTemplate, p_type, finalDamage <= 0 ? 0 : -finalDamage,
                                                   m_feedbackColor, p_bypassDefense ? Constants.PURPLE : Constants.TRANSPARENT,
                                                   m_feedbackPositionRandomness.x, m_feedbackPositionRandomness.y);
            }

            if (finalDamage > 0)
            {
                m_health.Damage(finalDamage, p_bypassImmunityWindow);
            }
        }

        // make sure the AI starts targeting its last damager (if it's an entity)
        if (m_ai && p_damager && p_damager.m_entity)
        {
            m_ai.m_target = p_damager.m_entity;
        }
    }
예제 #6
0
    public void Damage(Entity p_damager, int p_damage, bool p_bypassImmunityWindow)
    {
        if (m_health)
        {
            int finalDamage = p_damage;             // calculate defense, resistances, etc. and compile it into this variable

            if (finalDamage > 0)
            {
                m_health.Damage(finalDamage, p_bypassImmunityWindow);
            }
        }

        // make sure the AI starts targeting its last damager
        if (m_ai && p_damager)
        {
            m_ai.m_target = p_damager;
        }

        OnDamage();
    }
예제 #7
0
    public void HitCollider(Collider2D p_hit, Rigidbody2D p_rigid, bool p_knockbackLeft)
    {
        UnitHealth health = p_hit.GetComponent <UnitHealth>();

        if (health)
        {
            m_damageEvent.Invoke();
            health.Damage(m_damage.Value);

            if (p_rigid)
            {
                float   force    = m_knockbackValue.Value * 2;
                Vector2 velocity = new Vector2(force * 2, force / 3);
                int     flip     = p_knockbackLeft ? -1 : 1;

                velocity.x *= flip;

                p_rigid.velocity = velocity;
            }
        }
    }