Beispiel #1
0
    public void Damage(Vector3 knockbackDir, int damage, int knockbackForce)
    {
        unitKnockback.KnockBack(knockbackDir, knockbackForce);

        //playerHealth.Damage(damage);
        //playerHealth.Damage(damage);

        unitHealth.Damage(damage);
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        if (!enemyTransform)         //If target stops existing, destroy arrow and exit
        {
            Destroy(gameObject);
            return;
        }

        Vector3 direction = (enemyTransform.position - body.position);

        body.position += direction.normalized * speed * Time.deltaTime;
        Quaternion rotation = Quaternion.LookRotation(direction);

        rotation           = Quaternion.Euler(0, rotationSpeed * Time.deltaTime, 0);
        transform.rotation = rotation * transform.rotation;
        if (direction.magnitude < proximity)
        {
            HealthComponent enemyHealth = enemyTransform.gameObject.GetComponent <HealthComponent>();
            if (enemyHealth)
            {
                enemyHealth.Damage(killPower);
            }
            Destroy(gameObject);
        }
    }
Beispiel #3
0
    public void Update(float deltaTime, PlayerInputScript player)
    {
        AttackTimer += deltaTime;
        player.UpdateAttackInputVariables(AttackTimer >= blockAttackInputTime, AttackTimer > -blockNewAttackTime);
        if (!hasDamaged && AttackTimer >= damageTime)
        {
            Collider2D[] hits = player.ThrowAttack(attackPosition, attackSize);
            foreach (Collider2D hit in hits)
            {
                HealthComponent healthComponent = hit.GetComponent <HealthComponent>();
                if (healthComponent != null)
                {
                    healthComponent.Damage(damage, Vector2.zero);
                }
                EnemyHand enemyHand = hit.GetComponent <EnemyHand>();
                if (enemyHand != null)
                {
                    //Debug.Log("Test");
                    enemyHand.Damage(damage);
                }
            }
            hasDamaged = true;
        }

        if (AttackTimer >= attackLength)
        {
            player.EndAttack();
        }
    }
Beispiel #4
0
    // Update is called once per frame
    void Update()
    {
        if (!enemyTransform) //If target stops existing, destroy arrow and exit
        {
            Destroy(gameObject);
            return;
        }
        Vector3 direction = (enemyTransform.position - body.position);

        body.position += direction.normalized * speed * Time.deltaTime;
        Quaternion rotation = Quaternion.LookRotation(direction);

        rotation           = Quaternion.Euler(0, rotationSpeed * Time.deltaTime, 0);
        transform.rotation = rotation * transform.rotation;
        if (direction.magnitude < proximity)
        {
            for (int i = 0; i < enemyList.transform.childCount; i++)
            {
                Transform targetTransform = enemyList.transform.GetChild(i);
                if (Vector3.Distance(targetTransform.position, gameObject.transform.position) < splashRadius)
                {
                    HealthComponent targetHealth = targetTransform.gameObject.GetComponent <HealthComponent>();
                    if (targetHealth)
                    {
                        targetHealth.Damage(killPower);
                    }
                }
            }
            Destroy(gameObject);
        }
    }
Beispiel #5
0
    public override void Execute(HealthComponent t)
    {
        self_destruct = true;
        Collider2D[] hit = Physics2D.OverlapCircleAll((Vector2)this.transform.position, range);

        foreach (Collider2D c in hit)
        {
            HealthComponent h = c.gameObject.GetComponent <HealthComponent> ();
            if (h != null && UnitAIBehaviour.ObjectInMask(h.gameObject, layerTarget))
            {
                h.Damage(damage);
            }
        }

        HealthComponent self = this.GetComponent <HealthComponent> ();

        if (self != null)
        {
            self.Kill();
        }
        else
        {
            Destroy(this.gameObject);
        }
    }
Beispiel #6
0
        public void Update()
        {
            if (_timeSinceDamage < 1)
            {
                return;
            }

            _timeSinceDamage = 0;
            HealthComponent.Damage(DamagePerSecond);
        }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        HealthComponent victim = collision.gameObject.GetComponent <HealthComponent>();

        if (victim && victim.ownerComponent.owner != myOwner.owner && !victimsHit.Contains(victim))
        {
            victimsHit.Add(victim);
            victim.Damage(damage);
            particlePoolComponent.FireParticleSystem(ParticlePoolComponent.ParticleSystemType.ShipHit, transform.position, transform.eulerAngles.z + 180f);
        }
    }
 public bool HitScanDamage(DamageData damageData)
 {
     if (scanHit.collider != null)
     {
         HealthComponent health = scanHit.collider.GetComponent <HealthComponent>();
         if (health != null)
         {
             health.Damage(damageData);
             return(true);
         }
     }
     return(false);
 }
Beispiel #9
0
    // Update is called once per frame
    void Update()
    {
        Collider2D[] hit = Physics2D.OverlapCircleAll((Vector2)this.transform.position, range);

        foreach (Collider2D c in hit)
        {
            HealthComponent h = c.gameObject.GetComponent <HealthComponent>();
            if (h != null && UnitAIBehaviour.ObjectInMask(h.gameObject, targets))
            {
                h.Damage(damage * Time.deltaTime);
            }
        }
    }
Beispiel #10
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        GameObject other = collision.gameObject;

        if (other != null)
        {
            HealthComponent health = other.GetComponent <HealthComponent>();
            if (health != null)
            {
                health.Damage(amount);
            }
        }
    }
Beispiel #11
0
 protected void OnTriggerEnter2D(Collider2D collision)
 {
     if (!collision.CompareTag(this.tag))
     {
         HealthComponent health = collision.GetComponent <HealthComponent>();
         ActorController actor  = collision.GetComponent <ActorController>();
         if (health != null && actor != null && !health.invulnerable)
         {
             health.Damage(this.transform.parent.gameObject, damage, true);
             audioSource.Play();
         }
     }
 }
Beispiel #12
0
        private void OnTriggerEnter(Collider other)
        {
            // hit by obstacle, receive damage (except: god mode enabled)
            if (other.gameObject.CompareTag("Obstacle") && !_playerModel.DebugGodMode)
            {
                _health.Damage();
            }

            // hit by health pack, heal
            if (other.gameObject.CompareTag("HealthPack"))
            {
                _health.Heal();
            }
        }
Beispiel #13
0
    public void RayCastAttack(int damage, Vector2 knockback)
    {
        Vector3      dir       = transform.right * transform.root.localScale.x;
        Vector2      direction = new Vector2(dir.x, dir.y);
        RaycastHit2D hit       = Physics2D.Raycast(this.transform.position, direction, 100, layerMask);

        if (hit.collider != null)
        {
            HealthComponent health = hit.collider.transform.root.GetComponent <HealthComponent>();
            if (health != null)
            {
                health.Damage(damage, knockback);
            }
        }
    }
Beispiel #14
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.layer == 10 && canDashDamage && collision.GetComponentInParent <HealthComponent>() != null && collision.GetComponentInParent <EnemyController>() != null)
        {
            //if damage from dash is enabled i.e. we can "see" the enemy
            if (collision.GetComponentInParent <EnemyController>().canRecieveDamage)
            {
                enemyHealthComp = collision.GetComponentInParent <HealthComponent>();
                playerHealthComp.Heal(dashHealAmount);
                enemyHealthComp.Damage(dashDamage * playerController.DamageMultiplier);
            }


            uiManager.UpdateHealthSlider();
            //_uiManager.DamageHealthBar();
        }
    }
Beispiel #15
0
    // Update is called once per frame
    void Update()
    {
        if (Vector3.Distance(target.position, transform.position) < reachedGoal)
        {
            HealthComponent h = target.gameObject.transform.parent.GetComponent <HealthComponent>();
            if (h)
            {
                h.Damage(DamagePotential);
            }
            else
            {
                Debug.Log("No HealthComponent in " + target.gameObject.transform.parent.name);
            }

            Destroy(gameObject);
        }
    }
Beispiel #16
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.CompareTag("Collectibles"))
     {
         Debug.Log("uhhh...");
         SoundManager.instance.PlaySingle(collectSound);
         other.gameObject.SetActive(false);
     }
     else if (other.gameObject.CompareTag("Obstacle"))
     {
         hp.Damage();
     }
     else if (other.gameObject.CompareTag("Wall"))
     {
         Die();
     }
 }
Beispiel #17
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        HealthComponent target = collision.transform.root.GetComponent <HealthComponent>();

        if (target != null && !hasHit.Contains(target))
        {
            int direction = 1;
            if (knockBack != Vector2.zero)
            {
                direction = (int)Mathf.Sign(target.transform.position.x - moveHandler.transform.position.x);
            }
            Vector2 kb = knockBack;
            kb.x *= direction;
            float hitStun = moveHandler.GetHitStun();

            if (target.Damage(damage, kb, hitStun))
            {
                hasHit.Add(target);
                MoveHandler enemyHandler = target.GetComponent <MoveHandler>();
                moveHandler.HitEnemy(enemyHandler);
                if (enemyHandler != null)
                {
                    enemyHandler.HitDirection = direction;
                }
            }
        }

        /*EntityController target = collision.transform.root.GetComponent<EntityController>();
         * if (target != null)
         * {
         *      if (!entitiesHit.Contains(target.EntityID))
         *      {
         *              entityController.HitEnemy(target);
         *              int direction = 1;
         *              if (knockBack != Vector2.zero)
         *              {
         *                      direction = (int)Mathf.Sign(target.transform.position.x - entityController.transform.position.x);
         *              }
         *              target.Damage(damage,knockBack*direction);
         *              entitiesHit.Add(target.EntityID);
         *      }
         * }*/
    }
Beispiel #18
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        LocalPlayer newLocalPlayer = collision.gameObject.GetComponent <LocalPlayer>();

        if (newLocalPlayer)
        {
            localPlayer = newLocalPlayer;
            HealthComponent damage = collision.gameObject.GetComponent <HealthComponent>();

            if (localPlayer && localPlayer.onGround == false && isFrozen == true)
            {
                Debug.Log("Hit by player");

                Destroy(gameObject);
            }
            else if (!isFrozen && localPlayer)
            {
                damage.Damage(1);
            }
        }
    }
Beispiel #19
0
 void OnTriggerEnter2D(Collider2D info)
 {
     if (info.gameObject.layer == collisionLayers || info.gameObject.tag == "ground")
     {
         Destroy(gameObject);
     }
     if (info.gameObject.layer == LayerMask.NameToLayer("enemies"))
     {
         EnemyBase       basic           = info.gameObject.GetComponentInParent <EnemyBase>();
         HealthComponent healthComponent = info.gameObject.GetComponent <HealthComponent>();
         if (basic != null)
         {
             basic.velocity.x += (flySpeed / 6) * facing;
         }
         healthComponent.Damage(damageAmount);
         if (!bounced)
         {
             velocity.x *= -0.25f;
             velocity.y *= -0.25f;
             bounced     = true;
         }
     }
 }
    void FixedUpdate()
    {
        // Update grounded flag timer.
        m_groundedTimer = Mathf.Max(0.0f, m_groundedTimer - Time.fixedDeltaTime);

        // Calculate slope rotation.
        Quaternion slopeRotation    = Quaternion.identity;
        Quaternion slopeRotationInv = Quaternion.identity;

        if (m_grounded)
        {
            RaycastHit raycastGround;
            Physics.Raycast(new Ray(transform.position + new Vector3(0.0f, 0.5f, 0.0f), -transform.up), out raycastGround);

            slopeRotation    = Quaternion.FromToRotation(Vector3.up, raycastGround.normal);
            slopeRotationInv = Quaternion.Inverse(slopeRotation);
        }

        // Calculate planar velocity.
        Vector3 planarVelocity = m_rigidbody.velocity;

        planarVelocity   = slopeRotationInv * planarVelocity;
        planarVelocity.y = 0.0f;
        planarVelocity   = slopeRotation * planarVelocity;

        // Update movement velocity.
        if (m_move)
        {
            Vector3 velocityChange = slopeRotation * m_movementVelocity - planarVelocity;

            if (!m_grounded)
            {
                velocityChange = Vector3.ClampMagnitude(velocityChange, m_airControl * Time.fixedDeltaTime);
            }

            m_rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);
        }

        // Update jump velocity.
        m_jumpTimer = Mathf.Max(0.0f, m_jumpTimer - Time.fixedDeltaTime);

        if (m_jump)
        {
            if (m_grounded && m_jumpTimer == 0.0f)
            {
                float jumpForce = Mathf.Sqrt(2.0f * m_jumpHeight * Mathf.Abs(Physics.gravity.y));
                m_rigidbody.AddForce(new Vector3(0.0f, jumpForce, 0.0f), ForceMode.VelocityChange);

                m_jumpTimer = m_jumpCooldown;

                // Set a grounded timer to prevent grounded state from being
                // applied again before the collider lifts from the ground.
                m_groundedTimer = 0.1f;
            }
        }

        // Reset grounded flag.
        m_grounded = false;

        // Update the desired facing direction.
        if (!m_look)
        {
            if (m_move && m_rigidbody.velocity.magnitude >= 0.1f)
            {
                m_lookDirection = m_rigidbody.velocity.normalized;
            }
        }

        m_lookDirection.y = 0.0f;
        m_lookDirection.Normalize();

        // Update the rotation torque.
        float   angleChange  = AngleSigned(transform.forward, m_lookDirection, Vector3.up);
        Vector3 torqueChange = new Vector3(0.0f, angleChange, 0.0f) - m_rigidbody.angularVelocity;

        m_rigidbody.AddTorque(torqueChange, ForceMode.VelocityChange);

        // Make the character shoot.
        m_shootTimer = Mathf.Max(0.0f, m_shootTimer - Time.fixedDeltaTime);

        if (m_shoot)
        {
            if (m_shootTimer == 0.0f)
            {
                // Cast a ray from the shooting origin.
                Vector3 shootOriginWorld = transform.position + m_shootOrigin;

                RaycastHit hitResult;
                if (Physics.Raycast(shootOriginWorld, m_shootDirection, out hitResult, Mathf.Infinity))
                {
                    Debug.DrawLine(shootOriginWorld, hitResult.point, Color.red, 0.001f, false);

                    // Apply damage to hit entity.
                    if (hitResult.rigidbody)
                    {
                        HealthComponent health = hitResult.rigidbody.GetComponent <HealthComponent>();

                        if (health != null)
                        {
                            health.Damage(10, hitResult.point, -hitResult.normal * 10.0f);
                        }
                    }
                }
                else
                {
                    Debug.DrawRay(shootOriginWorld, m_shootDirection * 100.0f, Color.red, 0.001f, false);
                }

                m_shootTimer = m_shootDelay;
            }
        }

        // Reset character flags.
        m_move  = false;
        m_jump  = false;
        m_look  = false;
        m_shoot = false;
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        GameObject explosionRef = Resources.Load <GameObject>(AssetPaths.pref_explosion);

        //dealing damage code
        if (collision.GetComponentInParent <EnemyController>() && !collision.GetComponentInParent <EnemyController>().canRecieveDamage)
        {
            //if enemy, and has enemy controller, but cannot receive damage
            print("hit shield");
            if (isPlayerProj)
            {
                Destroy(gameObject);
            }
        }
        else if (collision.gameObject.layer == targetLayer && collision.GetComponentInParent <HealthComponent>() != null /*&& collision.gameObject.GetComponent<EnemyController>() && collision.gameObject.GetComponent<EnemyController>().canRecieveDamage*/)
        {
            //if enemy and health component exists
            print("Hit player");
            _healthComponent = collision.GetComponentInParent <HealthComponent>();

            if (_playerController && isPlayerProj)
            {
                _healthComponent.Damage(damage * _playerController.DamageMultiplier);
            }
            else
            {
                _healthComponent.Damage(damage);
            }

            if (_healthComponent.IsAlive())
            {
                Destroy(gameObject);
            }
            else
            {
                HitCounter();
            }
        }
        else if (collision.gameObject.layer == 13 && !isPlayerProj)
        {
            //if player melee attack to deflect
            //Destroy(gameObject);
            print("projectile reverted");
        }
        else if (collision.gameObject.layer == 14 && !isPlayerProj)
        {
            //if we are enemy projectile and run into playerproj layer
            //explode
            if (explosionRef)
            {
                Instantiate(explosionRef, transform.position, Quaternion.identity);
            }

            Destroy(gameObject);
            print("explode");
        }
        else if (gameObject.layer == 15 && collision.gameObject.layer == 15 && isPlayerProj)
        {
            //if we are enemyProj, and the other is enemyProj but WE have playerProj true, then explode and destroy
            if (explosionRef)
            {
                Instantiate(explosionRef, transform.position, Quaternion.identity);
            }

            Destroy(gameObject);
            print("explode");
        }
        else if (gameObject.layer == 15 && collision.gameObject.layer == 15 && !isPlayerProj && collision.GetComponent <ProjectileBehaviour>().isPlayerProj)
        {
            //if we are enmemyproj and they are enemyproj and our isPlayerProj is false but their isPlayerProj is true, then simply destroy.
            Destroy(gameObject);
        }
        else if (collision.gameObject.layer == 15 && isPlayerProj)
        {
            //if we are player proj and run into enemy proj
            Destroy(gameObject);
        }

        if (collision.gameObject.layer == 12)
        {
            //if environment blocker, destroy object
            Destroy(gameObject);
        }
    }
    // Update is called once per frame
    protected override void Update()
    {
        base.Update();

        if (beamActive)
        {
            if (beamTimer <= 0)
            {
                beamTimer = beamHitInterval;

                //RaycastHit2D[] hits = Physics2D.LinecastAll(line.GetPosition(0), line.GetPosition(1), ~(LayerMask.GetMask("Player")));
                // Check for hits in the middle of the beam and at each edge
                int layerMask = ~(1 << this.gameObject.layer);
                if ((1 << this.gameObject.layer) == LayerMask.GetMask("PlayerAttack"))
                {
                    layerMask = ~LayerMask.GetMask("Player");
                }
                else if ((1 << this.gameObject.layer) == LayerMask.GetMask("EnemyAttack"))
                {
                    layerMask = ~LayerMask.GetMask("Enemy");
                }

                RaycastHit2D[] hitsA = Physics2D.LinecastAll(line.GetPosition(0) + orientation * beamWidth / 2.0f, line.GetPosition(1) + orientation * beamWidth / 2.0f, layerMask);
                RaycastHit2D[] hitsB = Physics2D.LinecastAll(line.GetPosition(0), line.GetPosition(1), layerMask);
                RaycastHit2D[] hitsC = Physics2D.LinecastAll(line.GetPosition(0) - orientation * beamWidth / 2.0f, line.GetPosition(1) - orientation * beamWidth / 2.0f, layerMask);

                List <GameObject> hits = new List <GameObject>();

                for (int i = 0; i < hitsA.Length; i++)
                {
                    HealthComponent h = hitsA[i].collider.GetComponent <HealthComponent>();
                    if (h != null && !h.invulnerable)
                    {
                        h.Damage(this.transform.parent.gameObject, damagePerHit, false);
                        hits.Add(h.gameObject);
                        audioSource.Play();
                    }
                }

                for (int i = 0; i < hitsB.Length; i++)
                {
                    HealthComponent h = hitsB[i].collider.GetComponent <HealthComponent>();
                    if (h != null && !h.invulnerable && !hits.Contains(h.gameObject))
                    {
                        h.Damage(this.transform.parent.gameObject, damagePerHit, false);
                        hits.Add(h.gameObject);
                        audioSource.Play();
                    }
                }

                for (int i = 0; i < hitsC.Length; i++)
                {
                    HealthComponent h = hitsC[i].collider.GetComponent <HealthComponent>();
                    if (h != null && !h.invulnerable && !hits.Contains(h.gameObject))
                    {
                        h.Damage(this.transform.parent.gameObject, damagePerHit, false);
                        audioSource.Play();
                    }
                }
            }
            else
            {
                beamTimer -= Time.deltaTime;
            }
        }
    }