public void Knockback(LightSource lightSource) { if (lightSource is Player) { Transform player = lightSource.transform; Rigidbody playerRigidbody = player.GetComponent<Rigidbody>(); this.controllerRumble = player.GetComponent<ControllerRumble>(); // Calculate a knockback force pushing the player away from the enemy fish Vector2 distance = (player.position - gameObject.transform.position); Vector2 knockback = distance.normalized * knockbackForce; playerRigidbody.velocity = Vector3.zero; playerRigidbody.AddForce(knockback, ForceMode.Impulse); // Instantiate hit particles GameObject.Instantiate(hitParticles, player.position, Quaternion.Euler(0, 0, 0)); FlashColor(probeColorHit, hitFlashDuration); // Rumble the controller when the player hits a fish. controllerRumble.PlayerHitByFish(); // The player was just hit // lastTimeHit = Time.time; } }
public void Knockback(LightSource lightSource) { if (lightSource is Player) { Transform player = lightSource.transform; Rigidbody playerRigidbody = player.GetComponent <Rigidbody>(); this.controllerRumble = player.GetComponent <ControllerRumble>(); // Calculate a knockback force pushing the player away from the enemy fish Vector2 distance = (player.position - gameObject.transform.position); Vector2 knockback = distance.normalized * knockbackForce; playerRigidbody.velocity = Vector3.zero; playerRigidbody.AddForce(knockback, ForceMode.Impulse); // Instantiate hit particles GameObject.Instantiate(hitParticles, player.position, Quaternion.Euler(0, 0, 0)); FlashColor(probeColorHit, hitFlashDuration); // Rumble the controller when the player hits a fish. controllerRumble.PlayerHitByFish(); // The player was just hit // lastTimeHit = Time.time; } }
/// <summary> /// Invoked when the player is hit by a light source that is stronger than him /// </summary> protected override void OnKnockback(LightSource enemyLightSource) { // Calculate a knockback force pushing the player away from the enemy fish Vector2 distance = (Transform.position - enemyLightSource.Transform.position); Vector2 knockback = distance.normalized * movementBean.KnockbackForce; Rigidbody.velocity = Vector3.zero; Rigidbody.AddForce(knockback, ForceMode.Impulse); // If the player was hit by a fish if (enemyLightSource.CompareTag("Fish")) { GameObject.Instantiate(movementBean.FishHitParticles, transform.position, Quaternion.Euler(0, 0, 0)); controllerRumble.PlayerHitByFish(); } movementBean.LastTimeHit = Time.time; }
/// <summary> /// Called when the player is hit by a light source that is stronger than him /// </summary> public override void Knockback(LightSource enemyLightSource) { // Calculate a knockback force pushing the player away from the enemy fish Vector2 distance = (Transform.position - enemyLightSource.Transform.position); Vector2 knockback = distance.normalized * knockbackForce; Rigidbody.velocity = Vector3.zero; Rigidbody.AddForce(knockback, ForceMode.Impulse); // If the player was hit by a fish if (enemyLightSource.CompareTag("Fish")) { // Instantiate hit particles GameObject.Instantiate(fishHitParticles, transform.position, Quaternion.Euler(0, 0, 0)); FlashColor(probeColorHit, hitFlashDuration); // Rumble the controller when the player hits a fish. controllerRumble.PlayerHitByFish(); } // The player was just hit lastTimeHit = Time.time; }