// Side Detonator Attack public void SelfDetonatorAttack() { // Detect enemy in range of attack. Collider2D enemyCollider2D = Physics2D.OverlapCircle(attackPoint.position, attackRange, enemyLayers); if (enemyCollider2D) { Debug.Log(enemyCollider2D.name + " was attacked by self detonator part."); // TODO: Play the side detonator attack animation. // TODO: Implement damage to enemy health. (Use separate class?) // TODO: Implement small damage to player health. (Use separate class?) // Knockback opponent BotController controller = enemyCollider2D.GetComponentInParent <BotController>(); BotSensor sensor = enemyCollider2D.GetComponentInParent <BotSensor>(); if (controller != null) { Vector2 direction = sensor.GetPosition() - transform.position; controller.ApplyForce((direction.normalized * knockBackStrength) + (new Vector2(0.0f, upwardForce))); } } }
// Side Detonator Attack public void BlackHoleAttack() { // Detect enemy in range of attack. Collider2D enemyCollider2D = Physics2D.OverlapCircle(attackPoint.position, attackRange, enemyLayers); if (enemyCollider2D && isRunning) { if (!IsPartCoolingDown()) { ResetCooldownTimer(); Debug.Log(enemyCollider2D.name + " was attacked by Black Hole part."); // TODO: Play the Black Hole attack animation. // Pull opponent rapidly toward player BotController controller = enemyCollider2D.GetComponentInParent <BotController>(); BotSensor sensor = enemyCollider2D.GetComponentInParent <BotSensor>(); if (controller != null) { Vector2 direction = sensor.GetPosition() - transform.position; controller.ApplyForce(-1 * (direction.normalized * pullStrength)); } } } }
public override void Activate(GameObject parent)//we may split this up further if necessary with more layers of abstraction { base.Activate(parent); //SET UP animator = parent.GetComponent <Animator>(); rb = parent.GetComponentInParent <Rigidbody2D>(); sensor = parent.GetComponentInParent <BotSensor>(); enemyLayer = sensor.GetEnemyLayer(); //////////// //ACTION // Set trigger to play animation of sword rotating //animator.SetTrigger("swordAttack"); // add thrust to lunge bot forward Vector2 appliedForce = new Vector2(dir.x * sensor.GetNearestSensedBotDirection(), dir.y); rb.AddRelativeForce(appliedForce, ForceMode2D.Impulse); Vector2 attackPos = parent.transform.position + new Vector3(sensor.GetNearestSensedBotDirection(), 0, 0); //Should be cleaned up, but currently creates Vector2 for current position + 1 in direction of enemy Collider2D collision = Physics2D.OverlapCircle(attackPos, attackDistance); //Needs to attack only in front using swordPos if (collision.gameObject.layer == enemyLayer) { Debug.Log("collision"); BotController collisionController = collision.transform.GetComponent <BotController>(); collisionController.TakeDamage(damage); collisionController.ApplyForce(new Vector2(knockback * sensor.GetNearestSensedBotDirection(), 0)); } Debug.Log(parent.name + " performed attack ability"); }