private void OnCollisionStay(Collision other) { if (other.gameObject.CompareTag("Player") && healthComponent.IsAlive) { DamageController.ApplyDamage(other.gameObject, damage); } }
protected void CheckForDamageControllers() { Collider[] hitColliders = Physics.OverlapSphere(transform.position, explosiveRadius); foreach (Collider c in hitColliders) { RaycastHit r; if (Physics.Linecast(transform.position, c.transform.position, out r)) { DamageController dControl = c.GetComponent <DamageController>(); Rigidbody body = c.GetComponent <Rigidbody>(); // Returns 0 - 1 based on the distance between 0 and the explosiveRadius float normDistance = Mathf.InverseLerp(0, explosiveRadius, r.distance); // Add explosive force if (c.GetComponent <Rigidbody>()) { body.AddExplosionForce(explosiveForce, transform.position, explosiveRadius, 3.0F, ForceMode.Acceleration); } // Calculate damage if (dControl != null && !(dControl is Explosive)) { Debug.DrawLine(transform.position, r.point, Color.red, 1.5F); float damage = explosiveDamage - (explosiveDamage * normDistance); dControl.ApplyDamage(damage); } } } }
public override void Fire() { RaycastHit hit = base.CastRay(); if (hit.collider == null) { return; } Destroy(Instantiate(decals.DEBUGDecal, hit.point, Quaternion.LookRotation(hit.normal)) as GameObject, 2); DamageController dControl = hit.collider.GetComponent <DamageController>(); Rigidbody body = hit.collider.GetComponent <Rigidbody>(); if (body != null) { body.AddForceAtPosition(transform.forward * projectileForce, hit.point, ForceMode.Acceleration); } if (dControl == null) { return; } // TODO: We should only apply precision damage if we hit a "precision" spot, like a head float totalDamage = damage.baseDamage + (damage.isPrecision? damage.additivePrecisionDamage : 0); dControl.ApplyDamage(totalDamage); BroadcastWeaponFired(this); }
public void AttackAction() { Collider[] colliders = Physics.OverlapSphere(SwordAttackPosition.position, SwordAttackRange, EnemyLayers); // Debug.Log("Colliders count " + colliders.Length); foreach (var enemyCollider in colliders) { DamageController.ApplyDamage(enemyCollider.gameObject, swordAttackDamage); } }
private void ApplyDamageToArea() { Collider[] colliders = Physics.OverlapSphere(model.transform.position, model.range); // Debug.Log("Colliders count " + colliders.Length); foreach (var collider in colliders) { if (collider.gameObject.CompareTag("Player")) { DamageController.ApplyDamage(collider.gameObject, model.damage); } } }
public static void FireballCollision(Fireball fireball, Collision other) { if (other.gameObject.CompareTag(fireball.model.ownerTag)) { return; } if (other.gameObject.CompareTag(fireball.model.hitTag)) { DamageController.ApplyDamage(other.gameObject, fireball.model.damage); } Object.Destroy(fireball.gameObject); }
public void DamageController_DeathEventThrowsSuccessfully() { // Test Data List <string> deadEntities = new List <string>(); const string entityName = "Johnny"; // Create the controller, and track the entity's health for a low amount, so we can kill the test entity. DamageController <DamageUnitTest> testController = new DamageController <DamageUnitTest>(); testController.OnEntityDeath += (sender, args) => { deadEntities.Add((args as EntityDeathEventArgs).EntityId); }; testController.DamageManager.BeginTrackingDamage(entityName, 20); DamageUnitTest testDamage = new DamageUnitTest() { BaseHealth = 500 }; testController.ApplyDamage(entityName, testDamage); Assert.AreEqual(1, deadEntities.Count); Assert.AreEqual(entityName, deadEntities[0]); }