public void spawnProjectiles(float dTime) { if (projectileType == null) { return; } for (int i = 0; i < projectilesPerShot; ++i) { //TODO: calculate spread float actualSpread = calculateSpread(i, projectilesPerShot); //Vector3 direction = new Vector3 (Mathf.Cos (actualSpread+shotDirection), Mathf.Sin (actualSpread+shotDirection), 0.0f); Vector3 direction = shotDirection; GameObject g = Instantiate(projectileType, direction * projectileSpawnDistanceFromCenter + center + transform.position, Quaternion.identity); AbstractProjectile a = g.GetComponent <AbstractProjectile> (); Agent ag = gameObject.GetComponentInParent <Agent>(); if (a != null) { a.initialUpdate(ag, direction); } else { Debug.Log("Non-projectile projectile fired"); } } }
/// <summary> /// Generate particle effect, spawn bullet, then destroy after allotted time. /// For loop is specific to FuzzBuster but leaving it in here for now because we allow for loop index /// passed in /// </summary> /// <param name="shotPos">Vector position of where the shot is coming from</param> /// <param name="shotNormal">If we were able to calculate it based off the "preshot" this is the normal of what we think the imact will be</param> /// <param name="whatToHit">Layermask describing what to hit</param> /// <param name="layer">Indicates what layer the bullet should be apart of</param> /// <param name="bulletCount">How many bullets we want to spawn</param> protected override void GenerateShot(Vector3 shotPos, Vector3 shotNormal, LayerMask whatToHit, string layer, int bulletCount = 1) { // Needed for special -45 degree angle shots var projRotation = CompensateQuaternion(FirePoint.rotation); // Optional offsets only used if we have a 3 round burst shot like that of the FuzzBuster ultimate var yOffset = 0.25f; var xOffset = 0.25f; for (var i = 0; i < bulletCount; ++i) { var firePosition = FirePoint.position; // This calculation is necessary so the bullets don't stack on top of eachother var yAxis = Player.DirectionalInput.y; if (PointingWeaponAtAngle(yAxis)) { yOffset = 0.125f; // There is one single special case - when the player is facing right, and looking at 45 degrees. // Coorindates must then be +, - instead of all + or all - xOffset = 0.125f * (Player.FacingRight ? -1 : 1); } else if (yAxis > 0.8) { yOffset = 0f; xOffset = 0.25f; } else { yOffset = 0.25f; xOffset = 0f; } // Based off the offset place the bullet in a position so it doesn't overlap with another firePosition.y = FirePoint.position.y + (i > 0 ? (i % 2 == 0 ? yOffset : yOffset * -1) : 0); firePosition.x = FirePoint.position.x + (i > 0 ? (i % 2 == 0 ? xOffset : xOffset * -1) : 0); Transform bulletInstance = Instantiate(BulletPrefab, firePosition, projRotation) as Transform; //Parent the bullet to who shot it so we know what to hit (parents LayerMask whatToHit) AbstractProjectile projectile = bulletInstance.GetComponent <BulletProjectile>(); if (Mathf.Sign(shotPos.x) < 0) { Vector3 theScale = projectile.transform.localScale; theScale.x *= -1; projectile.transform.localScale = theScale; } //Set layermask of parent (either player or baddie) projectile.FromPlayerNumber = Player.PlayerNumber; projectile.SetLayerMask(whatToHit); projectile.gameObject.layer = LayerMask.NameToLayer(layer); projectile.Damage = Damage; projectile.MoveSpeed = BulletSpeed; projectile.MaxLifetime = MaxLifetime; projectile.Fire(shotPos, shotNormal); } }
/// <summary> /// Helper method to create an individual bomb which is apart of the carpet bombing run. /// Sets all the needed values /// </summary> private void CreateBomb(Vector2 position) { Transform bulletInstance = Instantiate(BulletPrefabs[(int)BulletType.ULT], position, Quaternion.identity) as Transform; AbstractProjectile projectile = bulletInstance.GetComponent <BulletProjectile>(); projectile.SetLayerMask(WhatToHit); projectile.gameObject.layer = LayerMask.NameToLayer(GameConstants.Layer_PlayerProjectile); projectile.Damage = Damage; projectile.MoveSpeed = BulletSpeed; projectile.MaxLifetime = 10f; projectile.Fire(Vector2.down, Vector2.up); }
protected void Fire() { Transform clone = Instantiate(BulletPrefab, ProjectileData.FirePoint.position, ProjectileData.FirePoint.rotation) as Transform; AudioManager.Instance.PlaySound("BasicShot"); // Parent the bullet to who shot it so we know what to hit (parents LayerMask whatToHit) AbstractProjectile projectile = clone.GetComponent <BulletProjectile>(); // Set layermask of parent (either player or baddie) projectile.SetLayerMask(ProjectileData.WhatToHit); projectile.Damage = 5; projectile.MaxLifetime = 10; projectile.Fire((FacingRight ? Vector2.right : Vector2.left), Vector2.up); Invoke("ResetAttack", 0.5f); }
/// <summary> /// Generate an explosive 360 degree circular shot outward without stopping baddie movement /// </summary> private void FireWhole() { foreach (var angle in _raycastAngles) { Transform clone = Instantiate(BulletPrefab, ProjectileData.FirePoint.position, ProjectileData.FirePoint.rotation) as Transform; // Parent the bullet to who shot it so we know what to hit (parents LayerMask whatToHit) AbstractProjectile projectile = clone.GetComponent <BulletProjectile>(); // Set layermask of parent (either player or baddie) projectile.SetLayerMask(ProjectileData.WhatToHit); projectile.Damage = 5; projectile.MoveSpeed = 12; projectile.MaxLifetime = 10; projectile.Fire(angle, Vector2.up); } _actionData.FiringAttack = false; }
private void Fire() { try { Transform clone = Instantiate(BulletPrefab, ProjectileData.FirePoint.position, ProjectileData.FirePoint.rotation) as Transform; // Parent the bullet to who shot it so we know what to hit (parents LayerMask whatToHit) AbstractProjectile projectile = clone.GetComponent <BulletProjectile>(); // Set layermask of parent (either player or baddie) projectile.SetLayerMask(ProjectileData.WhatToHit); projectile.Damage = BulletDamage; //5; projectile.MoveSpeed = BulletSpeed; //10; projectile.MaxLifetime = 10; projectile.Fire(Target.position - transform.position, Vector2.up); }catch (System.Exception e) { print("Caught exception for delayed firing because the player died literally inbetween 0.1 and 0.15 seconds. Catch and move on"); } }
private IEnumerator Fire(float delay, Vector3 pos, int damage) { yield return(new WaitForSeconds(delay)); var combinedPos = new Vector3(ProjectileData.FirePoint.position.x, pos.y, transform.position.z); Transform clone = Instantiate(BulletPrefab, combinedPos, transform.rotation) as Transform; AudioManager.Instance.PlaySound("BasicShot"); // Parent the bullet to who shot it so we know what to hit (parents LayerMask whatToHit) AbstractProjectile projectile = clone.GetComponent <BulletProjectile>(); // Set layermask of parent (either player or baddie) projectile.SetLayerMask(ProjectileData.WhatToHit); projectile.Damage = damage; projectile.MaxLifetime = 10; projectile.Fire((FacingRight ? Vector2.right : Vector2.left), Vector2.up); Invoke("ResetAttack", 0.5f); }
private void DropBomb() { CheckForOverPlayerShortCircuit(); InitiateAttack(); Transform clone = Instantiate(BulletPrefab, ProjectileData.FirePoint.position, ProjectileData.FirePoint.rotation) as Transform; // Parent the bomb to who shot it so we know what to hit (parents LayerMask whatToHit) AbstractProjectile projectile = clone.GetComponent <BulletProjectile>(); // Set layermask of parent (either player or baddie) projectile.SetLayerMask(ProjectileData.WhatToHit); projectile.Damage = 10; projectile.MoveSpeed = 10; projectile.MaxLifetime = 10; projectile.Fire(Vector2.down, (FacingRight ? Vector2.right : Vector2.left)); Invoke("ResetBombDrop", 0.5f); Invoke("ResetAttack", 0.5f); }
void OnTriggerEnter2D(Collider2D collider) { // Check to see if object is a projectile AbstractProjectile projectile = collider.GetComponent <AbstractProjectile>(); if (projectile == null && collider.tag != tag) { PlayerController player = collider.GetComponent <PlayerController>(); Enemy enemy = collider.GetComponent <Enemy>(); if (player != null) { player.GetHit(); } else if (enemy != null) { enemy.GetHit(); } Destroy(gameObject); } }
private void Fire() { try { foreach (var fp in _currentFirePoints) { Transform clone = Instantiate(BulletPrefab, fp.position, Quaternion.identity) as Transform; AudioManager.Instance.PlaySound("BasicShot"); // Parent the bullet to who shot it so we know what to hit (parents LayerMask whatToHit) AbstractProjectile projectile = clone.GetComponent <BulletProjectile>(); // Set layermask of parent (either player or baddie) projectile.SetLayerMask(ProjectileData.WhatToHit); projectile.Damage = 5; projectile.MoveSpeed = 12; projectile.MaxLifetime = 5; projectile.Fire(Target.position - transform.position, Vector2.up); } } catch (System.Exception e) { print("Caught Exception trying to Fire from Baddie " + gameObject.name + " Exception : " + e.Message); } }
/// <summary> /// Based off the attack type (counter or clockwise) generate a spiral attack /// starting at 0degrees and moving 45 degrees to 360. /// This attack stops baddie movement /// </summary> private void Fire() { try { Transform clone = Instantiate(BulletPrefab, ProjectileData.FirePoint.position, ProjectileData.FirePoint.rotation) as Transform; // Parent the bullet to who shot it so we know what to hit (parents LayerMask whatToHit) AbstractProjectile projectile = clone.GetComponent <BulletProjectile>(); // Set layermask of parent (either player or baddie) projectile.SetLayerMask(ProjectileData.WhatToHit); projectile.Damage = 5; projectile.MoveSpeed = 12; projectile.MaxLifetime = 10; projectile.Fire(_raycastAngles[_actionData.AngleIndex], Vector2.up); // _attackMode is either 1 or -1, so this allows for dynamic forward and backwards traversal of the array _actionData.AngleIndex = _actionData.AngleIndex + _actionData.AttackMode; if (_actionData.AngleIndex % 16 == 0 || _actionData.AngleIndex < 0) { _actionData.AngleIndex = 0; _actionData.FiringAttack = false; } }catch (System.Exception e) { print("Caught Exception trying to Fire from Baddie " + gameObject.name + " Exception : " + e.Message); } }
private void AddProjectile(AbstractProjectile projectile) { AddChildNode(projectile); projectile.Connect(nameof(AbstractProjectile.ProjectileHit), this, nameof(InstancePackedScene)); }