private void OnTriggerStay(Collider collision) { // Check Laser CollisionFOrBullet LaserBulletScript laserBullet = collision.gameObject.GetComponent <LaserBulletScript>(); if (laserBullet != null && laserBullet.isEnemyShot) { Vector3 collisionPoint = collision.ClosestPoint(transform.position); Vector3 collisionNormal = transform.InverseTransformDirection(collisionPoint - transform.position).normalized; if (!is3D) { // Convert to 2D tangent system collisionNormal = new Vector3(collisionNormal.x, 0f, collisionNormal.z); } if (isShielding && !IsFrontShot(collision.transform)) { // Get Effect for follow up shots every few frames if (Time.frameCount % GameConstants.BeamDamageRate == 0) { gameManager.BeginEffect(GameConstants.EffectTypes.ShieldHit, collisionPoint, collisionNormal); } } else { if (Time.frameCount % GameConstants.BeamDamageRate == 0) { gameManager.BeginEffect(GameConstants.EffectTypes.BulletHit, collisionPoint, collisionNormal); TakeDamage(laserBullet.damagePerSecond); } } laserBullet.CheckBeamCollisionStay(collisionPoint, collision.ClosestPoint(transform.position)); } }
private void OnTriggerEnter(Collider other) { LaserBulletScript laserBullet = other.gameObject.GetComponent <LaserBulletScript>(); ShotgunBulletScript shotgunBullet = other.gameObject.GetComponent <ShotgunBulletScript>(); BulletScript normalBullet = other.gameObject.GetComponent <BulletScript>(); Vector3 collisionPoint = other.ClosestPoint(transform.position); Vector3 collisionNormal = transform.InverseTransformDirection(collisionPoint - transform.position).normalized; gameManager.BeginEffect(GameConstants.EffectTypes.BulletHit, collisionPoint, collisionNormal).transform.SetParent(transform); if (laserBullet != null && !laserBullet.isEnemyShot) { HitByBullet(laserBullet.damage); laserBullet.OnHit(); } else if (shotgunBullet != null && !shotgunBullet.isEnemyShot) { HitByBullet(shotgunBullet.damage); shotgunBullet.OnHit(); } else if (normalBullet != null && !normalBullet.isEnemyShot) { HitByBullet(normalBullet.damage); normalBullet.OnHit(); } }
// private Vector3 lastKnownLocation = Vector3.zero; // Start is called before the first frame update void Start() { missileShot = GetComponent <AudioSource>(); if (projectile != null) { LaserBulletScript lbs = projectile.GetComponent <LaserBulletScript>(); if (lbs != null) { lbs.setSpeed(projectileSpeed); } } }
private void OnTriggerStay(Collider collision) { // Check Laser CollisionFOrBullet LaserBulletScript laserBullet = collision.gameObject.GetComponent <LaserBulletScript>(); if (laserBullet != null) { Vector3 collisionPoint = collision.ClosestPoint(transform.position); Vector3 collisionNormal = transform.InverseTransformDirection(collisionPoint - transform.position).normalized; gameManager.BeginEffect(GameConstants.EffectTypes.BulletHit, collisionPoint, collisionNormal).transform.SetParent(transform); laserBullet.CheckBeamCollisionStay(collisionPoint, collisionNormal); } }
public void OnShieldEnter(Vector3 normalVector, Vector3 startPoint) { // Create new Laser Bullet at Reflection Point GameObject reflectedObject = gameManager.GetBullet(GameConstants.GunTypes.LaserGun, endPoint); reflectedLaser = reflectedObject.GetComponent <LaserBulletScript>(); // Set same time as current laser reflectedLaser.isEnemyShot = !isEnemyShot; reflectedLaser.transform.position = startPoint; reflectedLaser.transform.forward = Vector3.Reflect(endPoint.forward, normalVector); reflectedObject.SetActive(true); reflectedLaser.FireLaser(); }
private void OnTriggerStay(Collider collision) { // Check Laser CollisionFOrBullet LaserBulletScript laserBullet = collision.gameObject.GetComponent <LaserBulletScript>(); if (laserBullet != null && !laserBullet.isEnemyShot) { Vector3 collisionPoint = collision.ClosestPoint(transform.position); Vector3 collisionNormal = transform.InverseTransformDirection(collisionPoint - transform.position).normalized; if (Time.frameCount % GameConstants.BeamDamageRate == 0) { gameManager.BeginEffect(GameConstants.EffectTypes.BulletHit, collisionPoint, collisionNormal).transform.SetParent(transform); HitByBullet(laserBullet.damagePerSecond); } laserBullet.CheckBeamCollisionStay(collisionPoint, collisionNormal); } }
public void Fire(bool isEnemy, Transform firedShip) { // Check if it can fire if (canFire) { switch (gunType) { case GameConstants.GunTypes.MachineGun: BulletScript newBullet = gameManager.GetBullet(gunType, transform).GetComponent <BulletScript>(); newBullet.transform.position = transform.position + transform.forward; newBullet.transform.rotation = transform.rotation; newBullet.isEnemyShot = isEnemy; newBullet.GetComponent <Rigidbody>().velocity = firedShip.GetComponent <Rigidbody>().velocity; newBullet.gameObject.SetActive(true); newBullet.FireBullet(); musicPlayer.clip = bulletSound; if (!musicPlayer.isPlaying) { musicPlayer.Play(); } // Set transform and set initial velocity of rigidbody component break; case GameConstants.GunTypes.ShotGun: // Do it for 5 shots for (int i = 0; i < 6; i++) { ShotgunBulletScript newShoutgunBullet = gameManager.GetBullet(gunType, transform).GetComponent <ShotgunBulletScript>(); newShoutgunBullet.transform.position = transform.position + transform.forward; newShoutgunBullet.transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y + Random.Range(-10f, 10f), transform.eulerAngles.z); newShoutgunBullet.isEnemyShot = isEnemy; // Set bullet velocity to ship velocity newShoutgunBullet.GetComponent <Rigidbody>().velocity = firedShip.GetComponent <Rigidbody>().velocity; newShoutgunBullet.gameObject.SetActive(true); newShoutgunBullet.FireShotgun(); } musicPlayer.clip = shotgunSound; if (!musicPlayer.isPlaying) { musicPlayer.Play(); } // Get 5-10 ShotGun Bullets from GameManager.ShotGunBulletPool // Give random spread to rotation/initial position // Set Initial Velocity of rigidbody break; case GameConstants.GunTypes.LaserGun: LaserBulletScript newLaserBullet = gameManager.GetBullet(gunType, transform).GetComponent <LaserBulletScript>(); newLaserBullet.transform.position = transform.position + transform.forward; newLaserBullet.transform.SetParent(transform); float randomY = transform.eulerAngles.y + (isEnemy ? Random.Range(-5f, 5f) : 0f); newLaserBullet.transform.eulerAngles = new Vector3(transform.eulerAngles.x, randomY, transform.eulerAngles.z); newLaserBullet.isEnemyShot = isEnemy; newLaserBullet.gameObject.SetActive(true); newLaserBullet.FireLaser(); musicPlayer.clip = laserSound; if (!musicPlayer.isPlaying) { musicPlayer.Play(); } break; } // Cannot fire and start Coroutine to be able to fire next canFire = false; StartCoroutine(ResetCanFire()); } }
private void OnTriggerEnter(Collider collision) { // HitLogic LaserBulletScript laserBullet = collision.gameObject.GetComponent <LaserBulletScript>(); ShotgunBulletScript shotgunBullet = collision.gameObject.GetComponent <ShotgunBulletScript>(); BulletScript normalBullet = collision.gameObject.GetComponent <BulletScript>(); // Convert BoundsToLocalSpace Vector3 collisionPoint = collision.ClosestPoint(transform.position); Vector3 collisionNormal = transform.InverseTransformDirection(collisionPoint - transform.position).normalized; if (!is3D) { // Convert to 2D tangent system collisionNormal = new Vector3(collisionNormal.x, 0f, collisionNormal.z); } // Check if the shot is from the front within a threshold 1.7f is north east to north west if (laserBullet != null && laserBullet.isEnemyShot) { if (isShielding && !IsFrontShot(collision.transform)) { // Calculate Normal Differently for laser beam collisionNormal = transform.InverseTransformDirection(selfCollider.ClosestPoint(collision.transform.position) - transform.position).normalized; // Spawn Effect and set its parent as ship gameManager.BeginEffect(GameConstants.EffectTypes.ShieldHit, collisionPoint, collisionNormal).transform.SetParent(transform); adaptiveShield.OnHit(collisionNormal, laserBullet.damage); laserBullet.OnShieldEnter(transform.TransformDirection(collisionNormal), collision.ClosestPoint(transform.position)); PlaySound(hitShieldSound); } else { // Get Effect for laser on initial shot gameManager.BeginEffect(GameConstants.EffectTypes.BulletHit, collisionPoint, collisionNormal).transform.SetParent(transform); TakeDamage(laserBullet.damage); laserBullet.OnHit(); PlaySound(hitPlayerSound); } } else if (shotgunBullet != null && shotgunBullet.isEnemyShot) { if (isShielding && !IsFrontShot(collision.transform)) { adaptiveShield.OnHit(collisionNormal, shotgunBullet.damage); gameManager.BeginEffect(GameConstants.EffectTypes.ShieldHit, collisionPoint, collisionNormal).transform.SetParent(transform); shotgunBullet.OnShield(transform.TransformDirection(collisionNormal)); PlaySound(hitShieldSound); } else { TakeDamage(shotgunBullet.damage); gameManager.BeginEffect(GameConstants.EffectTypes.BulletHit, collisionPoint, collisionNormal).transform.SetParent(transform); shotgunBullet.OnHit(); PlaySound(hitPlayerSound); } } else if (normalBullet != null && normalBullet.isEnemyShot) { if (isShielding && !IsFrontShot(collision.transform)) { adaptiveShield.OnHit(collisionNormal, normalBullet.damage); gameManager.BeginEffect(GameConstants.EffectTypes.ShieldHit, collisionPoint, collisionNormal).transform.SetParent(transform); normalBullet.OnShield(transform.TransformDirection(collisionNormal)); PlaySound(hitShieldSound); } else { TakeDamage(normalBullet.damage); gameManager.BeginEffect(GameConstants.EffectTypes.BulletHit, collisionPoint, collisionNormal).transform.SetParent(transform); normalBullet.OnHit(); PlaySound(hitPlayerSound); } } }
void OnTriggerStay2D(Collider2D other) { MovementScript movementScript = GetComponent <MovementScript> (); bool hit = false; int otherId = 1; Color hitCol = new Color(1f, .5f, 0f); if (!invincibilty) { if (other.tag == "Bullet") { BulletScript bulletScript = other.GetComponent <BulletScript> (); if (bulletScript.id == id) { return; } if (movementScript.team != 0 && bulletScript.team == movementScript.team) { return; } health -= bulletScript.damage; LaserBulletScript lbs = bulletScript.GetComponent <LaserBulletScript> (); if (lbs == null) { Destroy(other.gameObject); } if (!movementScript.isJuggernaut) { StartCoroutine(InvincibilityRoutine(30f)); } hit = true; otherId = bulletScript.id; //GetComponent<PlayerEnemyHandler> ().CreateNumber (transform.position, bulletScript.damage.ToString(), hitCol, .1f, 120f, 3f); LucyFreezeBulletScript lucyFreeze = other.GetComponent <LucyFreezeBulletScript> (); if (lucyFreeze != null) { movementScript.move_mult = Mathf.Max(lucyFreeze.slowMax, movementScript.move_mult - lucyFreeze.slowAmount); } } if (other.tag == "Enemy") { EnemyScript enemyScript = other.GetComponent <EnemyScript> (); if (enemyScript.id == id) { return; } if (movementScript.team != 0 && enemyScript.team == movementScript.team) { return; } float damage; if (enemyScript.type == 0) { health -= 25f; damage = 25f; } else { health -= 5f; damage = 5f; } if (gameObject.activeSelf) { StartCoroutine(InvincibilityRoutine(30f)); } hit = true; otherId = enemyScript.id; //GetComponent<PlayerEnemyHandler> ().CreateNumber (transform.position, damage.ToString(), hitCol, .1f, 120f, 3f); } if (hit) { GetComponentInChildren <AudioManager> ().Play(1); GetComponentInChildren <ParticleController> ().Play(3); GetComponent <Rigidbody2D>().MovePosition(transform.position + (Vector3.ClampMagnitude(-transform.position + other.transform.position * 10f, .25f))); } if (health <= 0f) { GameManager gameManager = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameManager> (); if (GameManager.gameMode == GAMEMODE.PVP) { ChildQueueController.player_profiles [id - 1].deaths++; ChildQueueController.player_profiles [otherId - 1].kills++; } GameObject[] playerTemp = GameObject.FindGameObjectsWithTag("Player"); // Crea Number GameObject killer = null; for (int i = 0; i < playerTemp.Length; i++) { if (playerTemp [i] == null) { continue; } if (playerTemp [i].GetComponent <MovementScript> ().player_num == otherId) { killer = playerTemp [i]; break; } } if (killer != null) { //killer.GetComponent<PlayerEnemyHandler>().CreateNumber(killer.transform.position,"+10% Damage", Color.red, .05f, 60f, 1f); } //Buff WeaponManager[] temp = FindObjectsOfType <WeaponManager> (); for (int i = 0; i < temp.Length; i++) { if (temp[i].player_num == otherId) { temp [i].weapons [0].personalDamageMult += .1f; } } if (GameManager.gameMode == GAMEMODE.PVP) { gameManager.playerKills [otherId - 1]++; } else if (GameManager.gameMode == GAMEMODE.PVE) { gameManager.enemyMult = Mathf.Floor(gameManager.enemyMult / .5f); gameManager.enemyMult *= .5f; //gameManager.enemyMult = 1f; } lives--; if (GameManager.gameMode == GAMEMODE.JUGGERNAUT) { lives = Mathf.Max(lives, 1); gameManager.juggernautPoints [otherId - 1]++; } GetComponent <PlayerEnemyHandler> ().Disband(); Instantiate(diePrefab, transform.position, Quaternion.identity); death.Play(); //Juggernaut if (GameManager.gameMode == GAMEMODE.JUGGERNAUT) { if (GetComponent <MovementScript> ().isJuggernaut) { killer.GetComponent <MovementScript> ().BecomeJuggernaut(); GetComponent <MovementScript> ().UnbecomeJuggernaut(); } } if (lives > 0) { gameManager.StartCoroutine(gameManager.RespawnPlayer(gameObject)); } else { ChildQueueController.player_profiles [id - 1].losses++; } stunStack = 0; stunText.text = ""; GetComponentInChildren <DanielShooterScript> ().Reset(); GetComponent <WeaponManager> ().input_active = true; gameObject.SetActive(false); } } }