private void ShootChargedBullet() { if (_chargedShotBullet == null) { return; } _playerChargedShotShootingPosition.RemoveChild(_chargedShotBullet); _playerBulletHolder.AddChild(_chargedShotBullet); float maxDamage = _chargedShotBullet.GetBulletDamage() + _currentDamageDiff; float mappedDamage = ExtensionFunctions.Map(_chargeWeaponCurrentScale, 0, chargeGunMaxScaleAmount, 0, maxDamage); _chargedShotBullet.SetBulletDamage(mappedDamage); _chargedShotBullet.SetGlobalPosition(_playerChargedShotShootingPosition.GetGlobalPosition()); _chargedShotBullet.SetGlobalScale(Vector2.One * _chargeWeaponCurrentScale); float currentRotation = _playerRoot.GetRotation(); _chargedShotBullet.SetGlobalRotation(currentRotation); _chargedShotBullet.SetAsDynamicBullet(); _chargedShotBullet.SetMode(RigidBody2D.ModeEnum.Rigid); float xVelocity = Mathf.Cos(currentRotation); float yVelocity = Mathf.Sin(currentRotation); _chargedShotBullet.LaunchBullet(new Vector2(xVelocity, yVelocity).Normalized()); _chargedShotBullet = null; bulletShot?.Invoke(_currentWeaponType); }
private void HandleWeaponShooting() { switch (_currentWeaponType) { case WeaponType.SingleShot: float currentRotation = _playerRoot.GetRotation(); float xVelocity = Mathf.Cos(currentRotation); float yVelocity = Mathf.Sin(currentRotation); ShootSingleShotBullet(new Vector2(xVelocity, yVelocity)); break; case WeaponType.Shotgun: ShootShotGunBullet(); break; case WeaponType.ChargeGun: { _chargeWeaponCurrentScale = 1; _chargedShotBullet = (ChargedBullet)playerChargedBulletPrefab.Instance(); _playerChargedShotShootingPosition.AddChild(_chargedShotBullet); _chargedShotBullet.SetGlobalPosition(_playerChargedShotShootingPosition.GetGlobalPosition()); _chargedShotBullet.SetAsStaticBullet(); _chargedShotBullet.SetMode(RigidBody2D.ModeEnum.Kinematic); } break; default: throw new ArgumentOutOfRangeException(nameof(_currentWeaponType), _currentWeaponType, null); } }
/// <summary> /// Shoot charged proyectile /// throught the main weapon. /// </summary> /// <returns>IEnumerator</returns> public IEnumerator ShootCharged() { GameObject ammo = SpawnAmmo("charged"); if (ammo != null) { Vector3 destination = _rayShooter.centerPoint; ChargedBullet bullet = ammo.GetComponent <ChargedBullet>(); // set bullet direction Vector3 aimSpot = _mainCamera.gameObject.transform.position; // adjust bullet direction if the player is moving or running. if (player.xDirection != "") { aimSpot = AdjustDestination(aimSpot); } // set bullet damage. bullet.damage = plasmaGunData.GetChargedDamageBaseValue(); bullet.criticRate = plasmaGunData.criticRate; // start charged animation. bullet.ChargeShoot(); player.isCharging = true; // wait until user release mouse button. do { aimSpot = _mainCamera.gameObject.transform.position; aimSpot += _mainCamera.gameObject.transform.forward * freeAiminDistance; yield return(new WaitForFixedUpdate()); } while (Input.GetMouseButton(0)); player.isCharging = false; if (bullet.readyToShoot) { bullet.ShootBullet(aimSpot, shootForce, player); bullet.PlayShootAnim(); // update plasma gun data. plasmaGunData.UpdatePlasma(true); // play shooting animation. player.playerAnim.SetTrigger("Shoot"); // display shooting particle effect. smoke.Play(); } else { bullet.RestoreBullet(); bullet.StopCharging(); bullet.ResetChargedBullet(); // shoot standard bullet. Shoot(); } _chargedShootRoutine = null; } }