void OnTriggerEnter(Collider other) // Applied on first hit. calculate knockback based on distance to center of explosion. !!Can bug out in certain situations if player is already inside the trigger and thus never enters it. maybe timestep issue, object disappears before next cycle?!! //void OnTriggerStay(Collider other) // knockback applied on every timestep as long as player is within radius, no need to calculate distance based force. Remember to apply damage just once. { // Explosion hits player if (other.tag == "Player") { /* TRYING SPLITTING PROJECTILE DAMAGE TO IMPACT AND SPLASH DAMAGE INSTEAD OF DEALING FULL DAMAGE ON DIRECT HIT AND THEN IGNORING THAT TARGET WHEN CALCULATING SPLASH DAMAGE * // Ignore player that got hit directly by the projectile * if (directHit == other.gameObject) * { * return; * } */ // Calculate knockback knockback = (other.transform.position - transform.position).normalized * knockbackForce; // Reduce knockback if further away? // Calculate splash damage //splashDamage = // Deal damage TargetDummy targetDummy = other.gameObject.GetComponent <TargetDummy>(); // Dummy for testing if (targetDummy != null) { // ... the enemy should take damage. (projectile splash damage) targetDummy.TakeDamage(splashDamage, knockback); // Hp drops to 0 after taking damage if (targetDummy.currentHealth <= 0) { //parentScript.PlayHitSounds(true); } else { //parentScript.PlayHitSounds(false); } } PlayerHealth playerHealth = other.gameObject.GetComponent <PlayerHealth>(); if (playerHealth != null) { // ... the enemy should take damage. playerHealth.TakeDamage(splashDamage, knockback); //playerHealth.TakeDamage(0, knockback); // 0 damage to players, for testin rocket jumps if (parentGameObject != other.transform.gameObject) // No hitsounds if self damage { // Hp drops to 0 after taking damage if (playerHealth.currentHealth <= 0) { //parentScript.PlayHitSounds(true); } else { //parentScript.PlayHitSounds(false); } } } } }
void HitDummy() { // Try and find an Health script on the gameobject hit. TargetDummy targetDummy = shootHit.collider.GetComponent <TargetDummy>(); if (targetDummy != null) { // Knockback calculated using position of the weapon, use camera location instead to get correct vector? //knockback = transform.forward.normalized * knockbackForce; // Knockback direction (normalized) * force //knockback = (shootHit.transform.position - transform.position).normalized * knockbackForce; // Same as before knockback = camera.transform.forward.normalized * knockbackForce; // ... the enemy should take damage. targetDummy.TakeDamage(damagePerShot, knockback); // Hp drops to 0 after taking damage if (targetDummy.currentHealth <= 0) { PlayHitSounds(true); } else { PlayHitSounds(false); } } }
public override void TriggerAbility() { //Ball Explosion Collider[] cols = Physics.OverlapSphere(transform.position, radius); foreach (Collider collider in cols) { TargetDummy t = collider.GetComponent <TargetDummy>(); if (t) { t.ShowHit(25); } //Send object away Rigidbody rb = collider.gameObject.GetComponent <Rigidbody>(); if (rb) { //Get Directional vector away from ball Vector3 dir = (rb.gameObject.transform.position - gameObject.transform.position).normalized; //Add force in that direction + some Y component rb.AddForce(new Vector3(dir.x, yVectorIncrease, dir.z) * forceAmount, ForceMode.Impulse); } } base.TriggerAbility(); }
private void DoAbility(Collider other) { if ((network && network.IsHost()) || !network) { Vector3 position = other ? other.gameObject.transform.position : transform.position; EventController.FireEvent(new WorldVFXMessage(WorldSpaceVFX.WorldVFXType.bomb, position)); if (network) { network.SendWorldVFX(WorldSpaceVFX.WorldVFXType.bomb, position, -1, parent.GetIdOfAbilityBall(this)); } //First radius Collider[] cols = Physics.OverlapSphere(transform.position, lastRadius); foreach (Collider collider in cols) { TargetDummy t = collider.GetComponent <TargetDummy>(); EntityHealth enemy = collider.GetComponent <EntityHealth>(); float sqrDist = (collider.transform.position - transform.position).sqrMagnitude; if (sqrDist <= firstRadius * firstRadius) { if (t) { t.ShowHit(75); } else if (enemy) { DoBombDamage(enemy, 75); } } else if (sqrDist <= secondRadius * secondRadius) { if (t) { t.ShowHit(50); } else if (enemy) { DoBombDamage(enemy, 50); } } else if (sqrDist <= lastRadius * lastRadius) { if (t) { t.ShowHit(50); } else if (enemy) { DoBombDamage(enemy, 50); } } } SoundManager.PlaySoundAt("Bomb Explosion", transform.position); } base.TriggerAbility(); }
public void Attacking_A_Target_Yields_A_Result() { // Arrange ICombatEntity target = new TargetDummy(); ICombatEntity attacker = new TargetDummy(); // Act ICombatResult result = attacker.PerformAttack(attacker.BasicAttack(target)); // Assert Assert.IsNotNull(result); }
public void Abilities_Can_Be_Added_To_An_Entity() { // Arrange ICombatEntity entity = new TargetDummy(); // Act IAbility defend = new DefendAbility(); entity.Abilities.Add(defend); // Assert Assert.IsTrue(entity.Abilities.Contains(defend)); }
public void An_Attack_Is_Logged_In_Global_Combat_Log() { // Arrange ICombatEntity target = new TargetDummy(); ICombatEntity attacker = new TargetDummy(); double logCount = GlobalLog.GetInstance().GetLogCount(); // Act attacker.PerformAttack(attacker.BasicAttack(target)); // Assert Assert.AreNotEqual(GlobalLog.GetInstance().GetLogCount(), logCount); }
public void Hitting_A_Target_Yields_A_Hit_Result() { // Arrange ICombatEntity target = new TargetDummy(); ICombatEntity attacker = new TargetDummy(); HitModifier guaranteedHit = new HitModifier() { Description = "GuaranteeHit", Value = 100 }; // Act ICombatResult result = attacker.PerformAttack(attacker.BasicAttack(target).ModifyHit(guaranteedHit)); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(HitResult)); }
IEnumerator Die() { if (this.gameObject.CompareTag("Enemy")) { managerScript.killCount++; TargetDummy target = this.gameObject.GetComponent <TargetDummy>(); target.DropAmmo(); } // Debug.Log("death"); yield return(new WaitForSeconds(deathTime)); Destroy(this.gameObject); }
/// <summary> /// This is the "main" /// </summary> /// <param name="args"> /// The args. ?? /// </param> public static void Main(string[] args) { logger.LogMessage += LogMessageHandler; var dummy1 = new TargetDummy("Kalle"); var dummy2 = new TargetDummy("Urban"); var drunkenness = new HitModifier() { Description = "Drunk", Value = -10 }; for (int i = 0; i < 10; i++) { dummy1.PerformAttack(dummy1.BasicAttack(dummy2).ModifyHit(drunkenness)); drunkenness.Value -= 10; } Console.ReadLine(); }
void Fire() { // Reset the timer. timer = 0f; // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. //shootRay.origin = transform.position; shootRay.origin = camera.transform.position; //fwd from camera shootRay.direction = transform.forward; // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { // Try and find an EnemyHealth script on the gameobject hit. //EnemyHealth enemyHealth = shootHit.collider.GetComponent<EnemyHealth>(); TargetDummy targetDummy = shootHit.collider.GetComponent <TargetDummy>(); // If the EnemyHealth component exist... if (targetDummy != null) { knockback = transform.forward * knockbackForce; // ... the enemy should take damage. targetDummy.TakeDamage(damagePerShot, knockback); PlayHitSounds(); } // PlayerHealth playerHealth = shootHit.collider.GetComponent <PlayerHealth>(); //CLEAN UP LATER if (playerHealth != null) { knockback = transform.forward * knockbackForce; // ... the enemy should take damage. playerHealth.TakeDamage(damagePerShot, knockback); PlayHitSounds(); } // // Impact effect Impact(); } // If the raycast didn't hit anything on the shootable layer... else { // Endpoint = camera.fwd + max distance } }
void OnTriggerEnter(Collider other) { GamePlayer targetPlayer = other.GetComponent <GamePlayer>(); if (targetPlayer != null && isServer) { targetPlayer.DamagePlayer(damage, owner); } TargetDummy targetDummy = other.GetComponent <TargetDummy>(); if (targetDummy != null && isServer) { targetDummy.DamageDummy(owner, damage); } DestroyBulletInSeconds(0); }
void Shoot() { isShooting = true; Debug.Log("PewPew"); gunAudio.PlayOneShot(gunShoot); animator.SetTrigger("Shoot"); muzzle.Play(); shotsFired++; Vector3 tDirection = playerCam.transform.forward; RaycastHit hit; if (Physics.Raycast(playerCam.transform.position, tDirection, out hit)) { hitObject = hit.transform.gameObject; Debug.Log(hitObject); if (hitObject.CompareTag("Enemy")) { killCount++; TargetDummy targetHP = hitObject.GetComponent <TargetDummy>(); targetHP.TakeDamage(); } } ammo--; isShooting = false; animator.SetTrigger("Shoot"); accuracy = killCount / shotsFired; }
public override void TriggerAbilityPlayer(Collider other) { TargetDummy t = other.GetComponent <TargetDummy>(); EntityHealth enemy = other.GetComponent <EntityHealth>(); if (t) { EventController.FireEvent(new WorldVFXMessage(WorldSpaceVFX.WorldVFXType.ice, t.transform.position, t.transform)); t.FreezeDummy(freezeDuration); } if (enemy && network && network.IsHost()) { EventController.FireEvent(new WorldVFXMessage(WorldSpaceVFX.WorldVFXType.ice, enemy.transform.position, enemy.transform)); network.SendTriggerdAbilityEvent(enemy.MyID, GameEvent.ABILITY_EVENT_FREEZE, freezeDuration); network.SendWorldVFX(WorldSpaceVFX.WorldVFXType.ice, enemy.transform.position, enemy.MyID, parent.GetIdOfAbilityBall(this)); } //Old Mehtod of using radius /*Collider[] cols = Physics.OverlapSphere(transform.position, radius); * * foreach (Collider collider in cols) * { * TargetDummy t = collider.GetComponent<TargetDummy>(); * * Debug.Log("Hit: " + collider.name); * * if (t) * { * EventController.FireEvent(new WorldVFXMessage(WorldSpaceVFX.WorldVFXType.ice, t.transform.position, t.transform)); * t.FreezeDummy(freezeDuration); * } * } */ base.TriggerAbility(); }
public override void TriggerAbilityPlayer(Collider other) { //If ally, give shields TargetDummy td = other?.GetComponent <TargetDummy>(); if (td) { td.TurnOnShield(); } else { if (!network || network.IsHost()) { EntityHealth entity = other?.GetComponentInParent <EntityHealth>(); if (entity) { int id = entity.MyID; EventController.FireEvent(new SendShieldMessage(id)); } } } base.TriggerAbilityPlayer(other); }
//void FireHitScan() //[Command] void CmdFireHitScan() { // Reset the timer. timer = 0f; // Set start position of line renderer & enable it if (beam) { beamLine.enabled = true; } // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. //shootRay.origin = transform.position; shootRay.origin = camera.transform.position; //fwd from camera shootRay.direction = transform.forward; // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { // Workaround for self hits. problem atleast with jumppads //<-- FIX. allow raycast to hit multiple targets + ignore shooter? + boolean for toggling multi target since only railgun hits mutiple targets if (transform.root.gameObject == shootHit.transform.gameObject) // Set layer locally? Start as enemy, change into player and then this new layer is ignored? should work as long as change isnt updated for other clients { // or just set starting point just outside of the players collider //return; } // // Try and find an Health script on the gameobject hit. TargetDummy targetDummy = shootHit.collider.GetComponent <TargetDummy>(); if (targetDummy != null) { // Knockback calculated using position of the weapon, use camera location instead to get correct vector? //knockback = transform.forward.normalized * knockbackForce; // Knockback direction (normalized) * force //knockback = (shootHit.transform.position - transform.position).normalized * knockbackForce; // Same as before knockback = camera.transform.forward.normalized * knockbackForce; // ... the enemy should take damage. targetDummy.TakeDamage(damagePerShot, knockback); // Hp drops to 0 after taking damage if (targetDummy.currentHealth <= 0) { PlayHitSounds(true); } else { PlayHitSounds(false); } } // If the Health component exist... PlayerHealth playerHealth = shootHit.collider.GetComponent <PlayerHealth>(); if (playerHealth != null) { knockback = camera.transform.forward.normalized * knockbackForce; // ... the enemy should take damage. playerHealth.TakeDamage(damagePerShot, knockback); // Hp drops to 0 after taking damage if (playerHealth.currentHealth <= 0) { // Last hit PlayHitSounds(true); } else { PlayHitSounds(false); } } // Set the second position of the line renderer to the point the raycast hit. if (beam) { beamLine.SetPosition(1, shootHit.point); } // Impact effect Impact(); } // If the raycast didn't hit anything on the shootable layer... else { // ... set the second position of the line renderer to the fullest extent of the gun's range. if (beam) { beamLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } } }
public void Hitting_A_Target_Yields_A_Result_With_Damage() { // Arrange, make target defenceless to guarantee a hit ICombatEntity target = new TargetDummy(); ICombatEntity attacker = new TargetDummy(); HitModifier guaranteedHit = new HitModifier() { Description = "GuaranteeHit", Value = 100 }; // Act HitResult result = attacker.PerformAttack(attacker.BasicAttack(target).ModifyHit(guaranteedHit)) as HitResult; // Assert Assert.IsTrue(result.InflictedDamage > 0); }
public void Hit_Chance_Can_Be_Decreased() { // Arrange ICombatEntity target = new TargetDummy(); ICombatEntity attacker = new TargetDummy(); // Act IAttackCommand attackCommand = attacker.BasicAttack(target); attackCommand.ModifyHit(new HitModifier() { Description = string.Empty, Value = -10 }); // Assert Assert.AreEqual(attackCommand.BaseHitChance - 10, attackCommand.GetFinalHitChance()); }
public void Hit_Chance_Can_Be_Modified() { // Arrange ICombatEntity target = new TargetDummy(); ICombatEntity attacker = new TargetDummy(); // Act IAttackCommand attackCommand = attacker.BasicAttack(target); attackCommand.ModifyHit(new HitModifier() { Description = string.Empty, Value = -10 }); attackCommand.ModifyHit(new HitModifier() { Description = string.Empty, Value = 20 }); attackCommand.MultiplyHit(new HitMultiplier() { Description = "testDivider", Value = .5 }); attackCommand.MultiplyHit(new HitMultiplier() { Description = "testDivider", Value = .5 }); // Assert Assert.AreEqual(Convert.ToInt32(((double)attackCommand.BaseHitChance + 10) / 4), attackCommand.GetFinalHitChance()); }
public void Performing_An_Attack_Created_By_Another_Entity_Yields_An_Exception() { // Arrange ICombatEntity target = new TargetDummy(); ICombatEntity attacker = new TargetDummy(); // Act // The Attacker performs an attack that is created by the target. // In other words the attacker commands another entity to perform an attack ICombatResult result = attacker.PerformAttack(target.BasicAttack(target)); // Assert // Assert is made by expecting exception Assert.IsNull(result); }
public void Hit_Chance_Can_Be_Multiplied() { // Arrange ICombatEntity target = new TargetDummy(); ICombatEntity attacker = new TargetDummy(); // Act IAttackCommand attackCommand = attacker.BasicAttack(target); attackCommand.MultiplyHit(new HitMultiplier() { Description = "testMultiplier", Value = 2 }); // Assert Assert.AreEqual(attackCommand.BaseHitChance * 2, attackCommand.GetFinalHitChance()); }