void OnTriggerEnter2D(Collider2D c)
    {
        EnemyDamager damager = c.gameObject.GetComponent <EnemyDamager>();

        if (damager != null)
        {
            camShake.Shake();
            if (c.gameObject.tag == "PlayerAttack" && !immuneToPlayerAttacks && !invincible && !damageIframes)
            {
                sprite.color = damageColour;
                health      -= damager.damage;
                iframeTimer  = iframeTime;
            }
            else if (c.gameObject.tag != "PlayerAttack" && !invincible && !damageIframes)
            {
                sprite.color = damageColour;
                health      -= damager.damage;
                iframeTimer  = iframeTime;
            }

            if (damageTimer < 0 && !damageIframes)
            {
                damageTimer = damageTime;

                knockbackVector = transform.position - damager.source.position;
                knockbackVector = knockbackVector.normalized;

                knockbackSpeed = damager.knockbackPower;

                float resistance = 1 - knockbackResistance;

                rb2d.AddForce(knockbackVector * Time.deltaTime * knockbackSpeed * resistance, ForceMode2D.Impulse);
            }
        }
    }
Esempio n. 2
0
    public void AttackTarget(Vector3 targetPosition)
    {
        EnemyDamager damager = Instantiate(enemyDamager, targetPosition, Quaternion.identity)
                               .GetComponent <EnemyDamager>();

        damager.SetSpawner(enemyDamageable);
    }
    void OnTriggerEnter2D(Collider2D c)
    {
        EnemyDamager damager = c.gameObject.GetComponent <EnemyDamager>();

        if (damager != null)
        {
            camShake.Shake();
            if (damageTimer < 0)
            {
                damageTimer = damageTime;

                knockbackVector = transform.position - damager.source.position;
                knockbackVector = knockbackVector.normalized;

                knockbackSpeed = damager.knockbackPower;

                float resistance = 1 - knockbackResistance;

                if (resistance != 0)
                {
                    numHits++;
                }

                rb2d.AddForce(knockbackVector * Time.deltaTime * knockbackSpeed * resistance, ForceMode2D.Impulse);
            }
        }
    }
        private void Awake()
        {
            // Setup damage
            damager               = gameObject.AddComponent <EnemyDamager>();
            damager.damage        = 6;
            damager.bypassIframes = true;
            damager.cooldown      = 1f / 3f;
            damager.type          = AttackTypes.Spell;

            // Shaman stone
            if (PlayerData.instance.GetBool(nameof(PlayerData.equippedCharm_19)))
            {
                damager.damage        = (int)(damager.damage * 4f / 3f);
                transform.localScale *= 1.25f;
            }

            // Rotation
            Vector3 angle = Vector3.RotateTowards(Vector3.one, target - transform.position, float.PositiveInfinity, float.PositiveInfinity);

            angle.z = 0;
            angle   = angle.normalized * 25f;

            transform.rotation = Quaternion.LookRotation(angle);
            transform.rotation = new Quaternion(0, 0, transform.rotation.z, transform.rotation.w);

            if (angle.x < 0)
            {
                transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
            }

            // Velocity
            rb2d             = GetComponent <Rigidbody2D>();
            rb2d.isKinematic = true;
            rb2d.velocity    = angle;
        }
        private void SpawnShadeOrb()
        {
            if (shadeOrb == null && Ref.Hero.transitionState == HeroTransitionState.WAITING_TO_TRANSITION)
            {
                shadeOrb = new GameObject();
                shadeOrb.SetActive(false);

                shadeOrb.AddComponent <ShadeOrb>();
                shadeOrb.AddComponent <NonBouncer>().active = true;

                EnemyDamager c = shadeOrb.AddComponent <EnemyDamager>();
                c.damage        = 3;
                c.cooldown      = 0.5f;
                c.type          = AttackTypes.Spell;
                c.bypassIframes = true;
                c.bypassStun    = true;

                // Required for collision events for some reason
                Rigidbody2D rb2d = shadeOrb.AddComponent <Rigidbody2D>();
                rb2d.isKinematic = true;

                CircleCollider2D col = shadeOrb.AddComponent <CircleCollider2D>();
                col.radius    = 0.5f;
                col.isTrigger = true;

                GameObject particles = ObjectCache.ShadeParticles;
                particles.SetActive(true);
                particles.transform.SetParent(shadeOrb.transform);

                shadeOrb.layer = (int)PhysLayers.HERO_ATTACK;
                shadeOrb.name  = "Shade Orb";
                shadeOrb.tag   = "Hero Spell";
                shadeOrb.transform.position = Ref.Hero.transform.position;
                shadeOrb.SetActive(true);
            }
        }
Esempio n. 6
0
 void Start()
 {
     dm            = GetComponent <EnemyDamager>();
     currentHealth = maxHealth;
     rb            = GetComponent <Rigidbody2D>();
 }