private void FireProjectiles() { if (timer == 0) { Vector2 slope = Game1.Instance.Link.Position - Position; slope = new Vector2(slope.X, -slope.Y); Vector2 unitVector = slope / (float)Math.Sqrt(Math.Pow(slope.X, 2) + Math.Pow(slope.Y, 2)); float middleProjectileAngle = (float)-((Math.Atan2(unitVector.X, unitVector.Y) * (180 / Math.PI)) - 90f); Vector2 middleProjectile = new Vector2(unitVector.X, -unitVector.Y); Vector2 upperProjectile = new Vector2((float)Math.Cos((middleProjectileAngle - EnemyConstants.AquamentusProjectileAngle) * Math.PI / 180), (float)-Math.Sin((middleProjectileAngle - EnemyConstants.AquamentusProjectileAngle) * Math.PI / 180)); Vector2 lowerProjectile = new Vector2((float)Math.Cos((middleProjectileAngle + EnemyConstants.AquamentusProjectileAngle) * Math.PI / 180), (float)-Math.Sin((middleProjectileAngle + EnemyConstants.AquamentusProjectileAngle) * Math.PI / 180)); projectile1.Fire(upperProjectile, Position); projectile2.Fire(middleProjectile, Position); projectile3.Fire(lowerProjectile, Position); Sprite = EnemySpriteFactory.Instance.CreateSpriteEnemyAquamentusMouthOpen(); } if (timer == EnemyConstants.AquamentusMouthOpenTime) { Sprite = EnemySpriteFactory.Instance.CreateSpriteEnemyAquamentus(); } timer++; if (timer >= EnemyConstants.AquamentusProjectileTime) { timer = 0; projectile1 = new AquamentusProjectile(); projectile2 = new AquamentusProjectile(); projectile3 = new AquamentusProjectile(); } }
public void Start() { IProjectile missile = _missileSpawner.SpawnProjectile(); missile.Fire(); IProjectile bullet = _bulletSpawner.SpawnProjectile(); bullet.Fire(); }
public override void NetShoot(IAmmoEffect effect, float delay, Vector3 startPosition, Vector3 rayDirection) { if (m_ProjectilePrefab != null) { IProjectile projectile = PoolManager.GetPooledObject <IProjectile>(m_ProjectilePrefab, false); InitialiseProjectile(projectile); Transform ignoreRoot = GetRootTransform(); if (projectile is NetBallisticProjectile netProjectile) { netProjectile.SetCatchup(delay, rayDirection * m_MuzzleSpeed, m_Gravity); } projectile.Fire(startPosition, rayDirection * m_MuzzleSpeed, m_Gravity, effect, ignoreRoot, m_Layers, firearm as IDamageSource); projectile.gameObject.SetActive(true); } base.NetShoot(effect, delay, startPosition, rayDirection); }
public override void Shoot(float accuracy, IAmmoEffect effect) { if (m_ProjectilePrefab != null) { IProjectile projectile = PoolManager.GetPooledObject <IProjectile>(m_ProjectilePrefab, false); InitialiseProjectile(projectile); Transform ignoreRoot = GetRootTransform(); //if (firearm.wielder != null) // ignoreRoot = firearm.wielder.gameObject.transform; // Get the forward vector Vector3 muzzlePosition = m_MuzzleTip.position; Vector3 startPosition = muzzlePosition; Vector3 forwardVector = m_MuzzleTip.forward; bool useCamera = false; if (firearm.wielder != null) { switch (m_UseCameraAim) { case UseCameraAim.HipAndAimDownSights: useCamera = true; break; case UseCameraAim.AimDownSightsOnly: if (firearm.aimer != null) { useCamera = firearm.aimer.isAiming; } break; case UseCameraAim.HipFireOnly: if (firearm.aimer != null) { useCamera = !firearm.aimer.isAiming; } else { useCamera = true; } break; } } if (useCamera) { Transform aimTransform = firearm.wielder.fpCamera.aimTransform; startPosition = aimTransform.position; forwardVector = aimTransform.forward; } // Get the direction (with accuracy offset) Vector3 rayDirection = forwardVector; float spread = Mathf.Lerp(m_MinimumSpread, m_MaximumSpread, 1f - accuracy); if (spread > Mathf.Epsilon) { Quaternion randomRot = UnityEngine.Random.rotationUniform; rayDirection = Quaternion.Slerp(Quaternion.identity, randomRot, spread / 360f) * forwardVector; } Ray ray = new Ray(startPosition, rayDirection); Vector3 hitPoint; if (PhysicsExtensions.RaycastNonAllocSingle(ray, out m_Hit, k_MaxDistance, m_Layers, ignoreRoot, QueryTriggerInteraction.Ignore)) { hitPoint = m_Hit.point; } else { hitPoint = startPosition + (rayDirection * k_MaxDistance); } if (useCamera) { Vector3 newDirection = hitPoint - muzzlePosition; newDirection.Normalize(); projectile.Fire(muzzlePosition, newDirection * m_MuzzleSpeed, m_Gravity, effect, firearm.wielder.gameObject.transform, m_Layers, firearm as IDamageSource); SendNetShootEvent(muzzlePosition, newDirection); projectile.gameObject.SetActive(true); } else { projectile.Fire(startPosition, rayDirection * m_MuzzleSpeed, m_Gravity, effect, ignoreRoot, m_Layers, firearm as IDamageSource); SendNetShootEvent(startPosition, rayDirection); projectile.gameObject.SetActive(true); } } base.Shoot(accuracy, effect); }