public void AttackCollider(Collider2D c, float dmg) { if (c == null) { return; } var entity = c.GetComponent <Entity>(); if (entity == null) { entity = c.GetComponentInParent <Entity>(); if (entity == null) { return; } } if (!entity.immortal) { Instantiate(coinPrefab, c.bounds.center, Quaternion.identity); OnHitSomething(); } Vector2 direction = (entity.transform.position - transform.position).normalized; // Make sure we are facing it before we attack it // if (Vector2.Dot(direction, attackDir.normalized) > -0.3f) { var collisionPoint = c.bounds.ClosestPoint(transform.position); Instantiate(redExplosion, collisionPoint, Quaternion.identity); entity.TakeDamage(dmg, direction * 50f); } }
public void ApplyEffect(Collider2D target) { Entity entity = target.gameObject.GetComponent <Entity>(); int baseDuration; switch (elementType) { case ElementType.FIRE: entity.TakeDamage(damage); break; case ElementType.ICE: float baseSpeedMod = (float)(0.5); // slow down by 50% baseDuration = 150; // ~5 seconds entity.ModifySpeed(baseSpeedMod, baseDuration * magnitude); entity.TakeDamage(damage); break; case ElementType.ROT: baseDuration = 90; // ~3 seconds entity.TakeDamage(damage, baseDuration); break; default: throw new Exception("Spell of unknown element encountered: " + elementType); } }
public void OnPlayerDamage(Entity owner, Entity target, AttackStats attackStats) { int targetLayer = target.gameObject.layer; if (targetLayer == LayerMask.NameToLayer("PlayerHitBox") && !m_Invincible) { target.TakeDamage(attackStats); //CheckDeath(); } else if (targetLayer == LayerMask.NameToLayer("EnemyHitBox") || targetLayer == LayerMask.NameToLayer("BrickHitbox")) { Player player = (Player)owner; if (targetLayer == LayerMask.NameToLayer("EnemyHitBox")) { AddFusionScore(m_Vitae / m_GameSettings.FusionHitRatio); } if (attackStats.type == AttackType.LIGHT) { player.OnLightAttackHit(target); } else { player.OnHeavyAttackHit(target); } } }
private void OnTriggerEnter2D(Collider2D coll) { if (coll.tag == "Wall") { if (SpawnEffectOnEnemyInsteadOfProjectile) { GetComponent <DeathAnimation>().Spawn(coll.transform.position); } else { GetComponent <DeathAnimation>().Spawn(transform.position); } Destroy(gameObject); return; } Entity hit = coll.GetComponent <Entity>(); if (hit != null) { if (Team != hit.Team) { hit.TakeDamage(1); if (SpawnEffectOnEnemyInsteadOfProjectile) { GetComponent <DeathAnimation>().Spawn(coll.transform.position); } else { GetComponent <DeathAnimation>().Spawn(transform.position); } Destroy(gameObject); } } }
void Fire() { muzzleFlash.Play(); shootSound.Play(); light.beginFlash(); RaycastHit hit; float xChange = Random.Range(-spread, spread); float yChange = Random.Range(-spread, spread); float zChange = Random.Range(-spread, spread); Vector3 fireDirection = transform.forward + Vector3.right * xChange + Vector3.up * yChange + Vector3.forward * zChange; if (Physics.Raycast(transform.position + Vector3.up * 1.5f, fireDirection, out hit)) { //Debug.Log(hit.transform.name); Entity entity = hit.transform.GetComponent <Entity>(); if (entity != null) { entity.TakeDamage(damage); //Debug.Log(entity.health); } GameObject impact = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impact, 1f); } }
public override void DoEffect(GameObject user, Vector2 direction = default(Vector2), float damage = 0, int ignore = 0) { if (direction == default(Vector2)) { return; } Collider2D collider = user.GetComponent <Collider2D>(); RaycastHit2D rayHit; Vector2 start = user.transform.position; Vector2 dest = start + direction; collider.enabled = false; rayHit = Physics2D.Linecast(start, dest); collider.enabled = true; if (rayHit.transform != null) { Entity ent = rayHit.transform.GetComponent <Entity>(); if (ent) { user.GetComponent <Entity>().health += Mathf.Min(damage, ent.health); ent.TakeDamage(damage); } } }
void Explode() { pooler.SpawnFromPool("Explosion", transform.position, transform.rotation); Collider[] colliders = Physics.OverlapSphere(transform.position, blastRadius); //Get all the nearby objects with which the explosion is colliding foreach (Collider nearbyObject in colliders) { Entity entity = nearbyObject.GetComponent <Entity>(); if (entity != null) { entity.TakeDamage(damage); pooler.SpawnFromPool("Blood Spatter", entity.transform.position, Quaternion.identity); } //Uncomment if I want to add force to explosion //Rigidbody rb = nearbyObject.GetComponent<Rigidbody>(); //if(rb != null) //{ // rb.AddExplosionForce(blastForce, transform.position, blastRadius); //} } gameObject.SetActive(false); }
public override void DoEffect(GameObject user, Vector2 direction = default(Vector2), float damage = 0, int ignore = 0) { if (direction == default(Vector2)) { return; } Collider2D collider = user.GetComponent <Collider2D>(); RaycastHit2D rayHit; Vector2 start = user.transform.position; collider.enabled = false; GameManager.singleton.DisableCardColliders(); rayHit = Physics2D.Raycast(start, direction); collider.enabled = true; GameManager.singleton.EnableCardColliders(); if (rayHit.transform != null) { Entity ent = rayHit.transform.GetComponent <Entity>(); if (ent) { ent.TakeDamage(damage); } } }
// Update is called once per frame protected virtual void Update() { transform.position = Vector2.MoveTowards(transform.position, targetMovingPosition, Time.deltaTime * speed); Vector2 direction = targetMovingPosition - (Vector2)transform.position; if (direction.magnitude >= 0.01f) { // make sure player is not attacking while moving animator.SetBool("isAttacking", false); //unit is moving, apply moving animation int movingAnimationIndex = DirectionToIndex(direction); animator.SetBool("isMoving", true); animator.SetFloat("movingDirection", (float)movingAnimationIndex); } else { //unit is not moving, apply idle animation animator.SetBool("isMoving", false); if (attackingInRange) { // handle attack animator.SetBool("isAttacking", true); } } if (attacking) { // if target is dead, we are no longer attacking it! if (ennemyTarget == null) { attacking = false; attackingInRange = false; animator.SetBool("isAttacking", false); } else { // define wether we are in range to melee attack ennemy unit // this is done thanks to a differential between unit position and ennemy position // ennemy entity holds an offset value to define how far from the center of it, this unit can melee attack it attackingInRange = (transform.position - ennemyTarget.transform.position).magnitude - ennemyTarget.offsetMeleeRangeForAttackers <= 0.1f; if (attackingInRange) { //stop moving, and attack targetMovingPosition = transform.position; //checking wether we are still in range of attackTimer += Time.deltaTime; if (attackTimer >= 60 / attackSpeed) { ennemyTarget.TakeDamage(damage); attackTimer = 0; } } else { targetMovingPosition = ennemyTarget.gameObject.transform.position; } } } }
void explode() { explodeLoc = transform.position; explodeSound.Play(); Collider[] hitColliders = Physics.OverlapSphere(explodeLoc, radius); foreach (Collider c in hitColliders) { Entity entity = c.transform.GetComponent <Entity>(); if (entity != null) { entity.TakeDamage(damage); } } // Destroy(gameObject); GameObject temp = Instantiate(impactEffect, explodeLoc, Quaternion.LookRotation(explodeLoc)); transform.Translate(0, 1000, 0); Destroy(temp, 1f); Destroy(gameObject, 1f); exploded = true; }
private void attack(Entity target, int damage) { if (target != null) { target.TakeDamage(damage); } }
void Explode(Entity target) { if (target != null) { target.TakeDamage(damage); // (bullet 에게) target 은 데미지를 받는다 } if (explodeOnImpact && !enemyBullet) { Collider2D[] targets = Physics2D.OverlapCircleAll(rb.position, explosionRange); foreach (Collider2D t in targets) { Enemy enemy = t.GetComponent <Enemy>(); if (enemy != null) { enemy.TakeDamage(damage); // (explode bullet 에게) enemy 는 데미지를 받는다 } Bullet bullet = t.GetComponent <Bullet>(); if (bullet != null && bullet != this) { bullet.Remove(); } } } Remove(); }
public virtual bool Attack(int dx, int dy) { // Check if the object is in range. if (Mathf.Pow(dx - x, 2) + Mathf.Pow(dy - y, 2) > Mathf.Pow(GetRange(), 2)) { // We are out of range. Abort! return(false); } // We are in range, so now check to see if there is any entity at the said position. Entity target = GetEntityAt(dx, dy); // If we didn't find a target, abort! if (target == null) { return(false); } // Apply damage to the target based on our attack. target.TakeDamage(GetAttack()); // Draw a line from us to the target. // Instantiate the line and get its line renderer component. LineRenderer line = Instantiate(GameController.instance.attackLinePrefab).GetComponent <LineRenderer> (); // Set the positions of the line. line.SetPositions(new Vector3[] { new Vector3(((float)x) + 0.7f, ((float)y) + 0.7f), new Vector3(((float)target.x) + 0.3f, ((float)target.y) + 0.3f) }); return(true); }
// Deal damage/knockback to target public void Hit(Entity target, Vector3 direction) { if (!target) { return; } if (target == lastHit && !multiHit) { return; } rateTimer = 0f; lastHit = target; // Tell owner that it got a hit if (owner) { owner.DidHit(); } // Send damage data to entity target.TakeDamage(data, direction, owner); onHit.Invoke(); timeLastHit = timer; }
private void Shoot() { player.loseChange(changeCost); RaycastHit hit; Physics.Raycast(camera.transform.position, camera.transform.forward, out hit, range); muzzleflash.Play(); if (TOW == TypeOfWeapon.Midas) { // Do specific Midas things... } if (hit.transform != null) { Debug.Log(hit.transform.name); Entity hitItem = hit.transform.gameObject.GetComponent <Entity>(); if (hitItem != null) { hitItem.TakeDamage(damage); } } }
IEnumerator Melee(Entity victim) { canMove = false; destination = transform.position; pathfinder.SetDestination(transform.position); float attackSpeed = 3; float percent = 0; bool hasAppliedDamage = false; if (entity.entityType == EntityType.Shambler) { entity.TriggerLunge(); } while (percent <= 1) { if (percent >= 0.5f && !hasAppliedDamage) { hasAppliedDamage = true; victim.TakeDamage(entity.meleeDamage, victim.transform.position + Vector3.up * 1.65f, Vector3.forward); } percent += Time.deltaTime * attackSpeed; yield return(null); } canMove = true; }
protected void CreateDamage(Entity entity) { if (unit.isPureStatus) { entity.TakeStatus(Status.ApplyStatus(unit.damageType, entity.unit.statusResist)); } else if (unit.isPureDOT) { CreateDOT(entity); } else { float defense = Damage.CalculateDefense(unit.damageType, unit.damageSource, entity.unit.resists); Damage.Packet packet = Damage.CalculateDamage(unit.damageType, unit.damage, defense, unit.critChance, unit.statusChance, entity.unit.statusResist, entity.unit.maxHealth); if (packet.isStatus) { entity.TakeStatus(packet.status); } if (entity.unit.canReflect) { CreateDamage(this); } entity.TakeDamage(packet.damage); } }
public override void UpdateState() { target = stateManager.GetComponent <StateManager_Minion>().GetTarget(); if (TargetNullCheck(target)) { return; } if (Time.time > lastAttack + attackRate) { lastAttack = Time.time; Entity entity = target.GetComponent <Entity>(); // Play SFX AudioSource audioSource = GetComponent <AudioSource>(); if (audioSource != null) { audioSource.Play(); } if (entity != null) { if (entity.TakeDamage(damage)) { stateManager.GetComponent <StateManager_Minion>().RemoveTarget(target); GameObject.Destroy(target); } } } }
IEnumerator Attack() { currentState = State.Attacking; pathfinder.enabled = false; Vector3 originalPosition = transform.position; Vector3 dirToTarget = (target.position - transform.position).normalized; Vector3 attackPosition = target.position - dirToTarget * (myCollisionRadius); float attackSpeed = 3; float percent = 0; skinMaterial.color = Color.red; bool hasAppliedDmg = false; while (percent <= 1) { if (percent >= .5f && !hasAppliedDmg) { hasAppliedDmg = true; playerEntity.TakeDamage(damage); } percent += Time.deltaTime * attackSpeed; float interpolation = (-Mathf.Pow(percent, 2) + percent) * 4; transform.position = Vector3.Lerp(originalPosition, attackPosition, interpolation); yield return(null); } skinMaterial.color = originalColour; currentState = State.Chasing; pathfinder.enabled = true; }
void OnEnemyDamage(Entity owner, Entity target, AttackStats stats) { if (target.gameObject.layer == LayerMask.NameToLayer("EnemyHitBox")) { target.TakeDamage(stats); } }
/// <summary> /// Damages the all the target colliders. /// </summary> /// <param name="caster"> The entity that is attacking. </param> /// <param name="targets"> Targets of entity. </param> public static void DamageTargets(Entity caster, Collider2D[] targets) { if (targets.Length == 0) { // If there is no object in collider list , we want to play miss sound effect. AudioManager.instance.PlayAudioSourceOneShot(caster.entityAudioList[0]); return; } // If there is entities in list , we want to damage them. int i; for (i = 0; i < targets.Length; i++) { // First we need to check if target is enemy or breakable item. if (GetTargetType(targets[i].gameObject) == "Entity") { // If the target is entity. Entity e = targets[i].GetComponent <Entity>(); AudioManager.instance.PlayAudioSourceOneShot(AudioManager.instance.entityAudioList[0]); int damageTaken = e.TakeDamage(caster.damage); EffectManager.instance.CreateFadingText(targets[i].transform.position, "-" + damageTaken, Color.red); } else { targets[i].GetComponent <Breakable>().TakeHit(); } } }
IEnumerator Attack() { state = State.Attacking; pathFinder.enabled = false; Vector3 originalPos = transform.position; Vector3 directionToTarget = (target.position - transform.position).normalized; Vector3 attackPos = target.position - directionToTarget * (collisionRadius); float attackSpeed = 3; skinMaterial.color = Color.red; bool hasAppliedDamage = false; float percent = 0; while (percent <= 1) { if (percent >= 0.5f && !hasAppliedDamage) { hasAppliedDamage = true; targetEntity.TakeDamage(attackDamage); } percent += Time.deltaTime * attackSpeed; float interpolation = (-Mathf.Pow(percent, 2) + percent) * 4; transform.position = Vector3.Lerp(originalPos, attackPos, interpolation); yield return(null); } skinMaterial.color = skinOriginalColor; pathFinder.enabled = true; state = State.Chasing; }
public void Attack(Entity enemy) { if (enemy != null) { float distToEnemy = Vector3.Distance(this.transform.position, enemy.transform.position); if (distToEnemy > attackRange) { nextDamageEvent = Time.time + 1 / attackSpeed; rodentController.MoveTo(enemy.transform.position); } else { rodentController.MoveTo(rodentController.transform.position); Vector3 relativePos = enemy.transform.position - transform.position; Quaternion lookTowards = Quaternion.LookRotation(relativePos); transform.rotation = Quaternion.Lerp(transform.rotation, lookTowards, Time.deltaTime * 5f); if (Time.time >= nextDamageEvent) { nextDamageEvent = Time.time + 1 / attackSpeed; enemy.TakeDamage(this.attackDamage); } } this.actionQueue.Enqueue(new AttackAction(enemy)); } }
// Causes entity to take damage public void Hit(int baseDamage) { // Calculate damage taken, then tell the entity to take that damage float totalDamage = baseDamage * m_damageMod; entity.TakeDamage(totalDamage); }
public override void Activate(Entity target) { if (user.Atk + r.Next(0, 101) >= 75) { target.TakeDamage((target.Health / 2) + target.Def); } }
private void OnTriggerEnter(Collider other) { // Ignore all the ignore raycast objects. if (other.gameObject.layer != 2) { shot = false; Collider[] hitColliders = Physics.OverlapSphere(transform.position, explosionRadius); foreach (Collider c in hitColliders) { Entity entityScript = c.gameObject.transform.root.GetComponent <Entity>(); if (entityScript != null) { int scaledDamage = (int)(damage * (1 - Vector3.Distance(c.transform.position, transform.position) / explosionRadius)); if (scaledDamage > 0) { entityScript.TakeDamage(scaledDamage, shooterID); } } } StartCoroutine(AnimateExplosion()); } }
public void OnTriggerEnter(Collider other) { Entity en = other.GetComponent <Entity>(); if (en != null && en.transform.tag != "Player") { en.TakeDamage(equippable.damage); if (en.GetComponent <Animal>() != null) { if (en.GetComponent <Animal>().type == Animal.Types.Aggresive) { en.GetComponent <Animal>().state = Animal.States.Attack; } else if (en.GetComponent <Animal>().type == Animal.Types.Passive) { en.GetComponent <Animal>().state = Animal.States.Run; } } } if (other.tag != "Player") { Destroy(gameObject); } }
void OnTriggerEnter2D(Collider2D col) { if (col.gameObject == shooter) { return; } if (col.isTrigger) { return; } Entity e = col.GetComponent <Entity>(); if (e != null) { e.TakeDamage(damage); if (bloodEffect) { Instantiate(bloodEffect, transform.position, transform.rotation); } } if (col.GetComponent <Bullet>()) { return; } Destroy(gameObject); }
protected virtual void LaunchImpact(float angle, Vector2 contactPoint, Collider2D other) { if (launcher.GetLaunchImpactAnimation() != null) { Transform impact = Instantiate(launcher.GetLaunchImpactAnimation()).transform; impact.parent = ParticleGenerator.holder; impact.position = contactPoint; impact.eulerAngles = Vector3.forward * angle; } if (launchTrail != null) { launchTrail.CutLaunchTrail(); } Entity otherDamageable = other.attachedRigidbody.gameObject.GetComponent <Entity>(); float damage = launcher.GetLaunchDamage(); if (healthComponent.CurrentRatio < 0.5) { damage *= 2f; } otherDamageable?.TakeDamage(damage, contactPoint, launcher, 1f, true); TakeDamage(damage, contactPoint, launcher, 1f, true); launched = false; if (CameraControl?.GetPanTarget() == transform) { CameraControl.Pan(null); } }
IEnumerator Attack() { State bufState = currentState; currentState = State.Attacking; pathfinder.enabled = false; skinMaterial.color = attackColor; Vector3 originPos = transform.position; Vector3 dirToTarget = (target.position - transform.position).normalized; //not to enter each other's rigidbodies + dist to attack Vector3 attackPos = target.position - dirToTarget * (collisionRadius); float percent = 0; bool hasAppliedDamage = false; while (percent <= 1) { if (percent >= .5 && !hasAppliedDamage) { hasAppliedDamage = true; targetEntity.TakeDamage(attackDamage); } //skip frame between each step percent += Time.deltaTime * attackSpeed; //from 0 to 1 and after from 1 to 0 float interpolation = (-percent * percent + percent) * 4; transform.position = Vector3.Lerp(originPos, attackPos, interpolation); yield return(null); } skinMaterial.color = originalColor; currentState = bufState; pathfinder.enabled = true; }
public override void Execute(Entity parEntity) { if (canAttack) { Debug.Log("simple Attack"); parEntity.TakeDamage(this._damage); this.GetComponent<Entity>().TakeBreathCost(this._damageToBreath, this._breathMultiplier); _currentCoolDown = 0; parEntity.transform.DOShakeScale(0.7f, 1, 10).OnComplete(() => parEntity.transform.DOKill(true)); } }
private void resolveAttack(Entity other) { // TODO: Add a timer-thing, so this method is not called every frame. Maybe use Coroutines. bool kill = other.TakeDamage(_entity.Stats.Attack); if (kill) // Prevent the enemy from hurting the player, if the player kills it first. { disengageAttack(other); other.Die(); _entity.Stats.ScoreValue += other.Stats.ScoreValue; _entity.Stats.Experience += other.Stats.Experience; return; } bool died = _entity.TakeDamage(other.Stats.Attack); if (died) _entity.Die(); }
public void Attack(Entity entity) { entity.TakeDamage(Strength); }
public override void Execute(Entity parEntity) { parEntity.TakeDamage(this._damage); //this.GetComponent<Entity>().TakeBreathCost(this._damageToBreath, this._breathMultiplier); parEntity.transform.DOShakeScale(0.7f, 1, 10).OnComplete(() => parEntity.transform.DOKill(true)); }