private IEnumerable <Wait> Shoot(Creature user, Tile tile, Point velocity) { Bullet bullet = new BulletTrail(user.World, SpriteLoader.Instance.AddSprite("content/bullet_wave2"), Vector2.Zero, ColorMatrix.TwoColor(Color.Blue, Color.PaleTurquoise), Color.DarkBlue, 0); Projectile projectile = new Projectile(bullet); projectile.ExtraEffects.Add(new ProjectileImpactAttack(BulletAttack)); projectile.ExtraEffects.Add(new ProjectileCollideSolid()); return(projectile.ShootStraight(user, tile, velocity, 3, MaxDistance)); }
protected virtual void generateTrail(float distance = -1F) { float angle = Mathf.Atan2(shootDir.y, shootDir.x) * Mathf.Rad2Deg; Quaternion lookRotation = Quaternion.AngleAxis(angle, Vector3.forward); GameObject bulletObj = Instantiate(bulletTrailPrefab, firePoint.position, lookRotation) as GameObject; BulletTrail trail = bulletObj.GetComponent <BulletTrail> (); trail.distance = distance; trail.startPos = firePoint.position; }
public sealed override void OnSpawn() { if (BulletTrailInfo.UseTrail) { CurrentBulletTrail = BulletTrail.SpawnBulletTrail(this); } else { CurrentBulletTrail = null; } OnBulletSpawn(); }
private void Shoot() { Vector3 targetCenter = Helper.GetCenter(GameConstants.playerVariable.gameObject); Vector3 origin = this._weapon.transform.position; Vector3 direction = targetCenter - origin; Vector3 tmp; RaycastHit hitInfo; bool hitSomething = false; if (Physics.Raycast(origin, tmp = direction + this.Spread(), out hitInfo, this._maxBulletDistance.Value, this._shootLayerMask.value)) { // On the first shot, the bullet shouldn't touch the player so he has time to think if (this._firstShoot) { if (hitInfo.collider != GameConstants.playerVariable.collider) hitSomething = true; else { bool shot = false; int count = 0; while (++count < 10 && (shot = Physics.Raycast(origin, tmp = direction + this.Spread() * count, out hitInfo, this._maxBulletDistance.Value, this._shootLayerMask.value))) { if (hitInfo.collider != GameConstants.playerVariable.collider) break; } if (count >= 10) return; if (shot) hitSomething = true; } // The raycast hasn't touched the player, so we can continue! this._firstShoot = false; } else hitSomething = true; } this._gunshotEvent.Invoke(); if (hitSomething && hitInfo.collider == GameConstants.playerVariable.collider) this._playerShotEvent.Invoke(); // FX BulletTrail bulletTrail = GameConstants.bulletTrailPool.Request().GetComponent<BulletTrail>(); if (hitSomething) tmp = hitInfo.point; else tmp = origin + tmp * this._maxBulletDistance.Value; bulletTrail.SetPoints(origin, tmp); bulletTrail.Display(); Debug.DrawRay(origin, tmp, Color.red, this._shootTime.Value); }
protected override void Shoot(Transform shootPoint) { Vector3 trailTarget = shootPoint.transform.position + shootPoint.forward * _maxDistance; if (Physics.Raycast(new Ray(_aimingCamera.transform.position, _aimingCamera.transform.forward), out RaycastHit target, _maxDistance)) { if (target.collider.gameObject.TryGetComponent(out DamageReceiver destroyable)) { destroyable.TakeShot(_damage); } } BulletTrail trail = Instantiate(_trailPrefab, shootPoint.position, Quaternion.identity); trail.Init(trailTarget); }
void FireAt(BaseUnit target) { if (Time.time > timeUntilReload) { target.DealDamage(15); if (bulletTrail) { GameObject go = (GameObject)Instantiate(bulletTrail, transform.position, transform.rotation); BulletTrail bt = go.GetComponent <BulletTrail>(); bt.begin = transform.position; bt.end = target.transform.position; } timeUntilReload = Time.time + 0.5f; } }
private void Bullet(Vector2 start, Vector2 end, ParticleSystem splash) { GameObject o = new GameObject(); o.name = "Bullet"; o.transform.position = end; BulletTrail trail = o.AddComponent <BulletTrail>(); trail.Material(Game.Instance.world.spriteMat); trail.Start(start); trail.End(end); if (splash != null) { trail.Particle(splash); } }
public override IEnumerator FireEnum(GameObject myWeapon, Camera myCamera, EquipmentInventory myWeaponManager) { if (ammo > 0) { notCounter = rateOfFire; RaycastHit hit; for (int i = 0; i < pellets; i++) { Vector3 forwardVector = Vector3.forward; float deviation = Random.Range(0f, maxDeviation); float angle = Random.Range(0f, 360f); forwardVector = Quaternion.AngleAxis(deviation, Vector3.up) * forwardVector; forwardVector = Quaternion.AngleAxis(angle, Vector3.forward) * forwardVector; forwardVector = myWeapon.transform.rotation * forwardVector; if (Physics.Raycast(myWeapon.transform.position, forwardVector, out hit, range)) { Debug.DrawRay(myWeapon.transform.position, forwardVector * hit.distance, Color.yellow); // damage target or create decal or whatever. Debug.Log(hit.transform.name); } //create a bullet trails pool which can be pulled from for any weapon? BulletTrail = ObjectPoolingManager.Instance.GetObject("bullet"); BulletTrail.SetActive(true); BulletTrail.GetComponent <MusselEffect>().SetPositions(myWeapon.transform.position, hit.point); } ammo--; ApplyRecoil(myWeapon); //ApplyRecoil(myCamera.gameObject); } else { Debug.Log("weapon empty"); Reload(myWeaponManager); //Click empty } yield return(null); while (notCounter <= rateOfFire && notCounter > 0) { notCounter -= Time.deltaTime; //Debug.Log("weapon not ready: "+counter.ToString()); yield return(null); } }
void FireWeapon() { audioSource.Play(); shooting = false; canShoot = Time.time + 1 / fireRate; int dir = 0; for (int i = 0; i < 5; i++) { if (i > 0) { if (i % 2 == 0) { dir *= -1; } else { dir = (dir + 10) * (-1); } muzzleTransform.localEulerAngles += new Vector3(0, dir, 0); } RaycastHit hit; if (Physics.Raycast(muzzleTransform.position, muzzleTransform.forward, out hit, Mathf.Infinity, layerMask)) { Debug.DrawRay(muzzleTransform.position, muzzleTransform.forward * hit.distance, Color.red, 2f); if (hit.transform.CompareTag("Enemy")) { hit.transform.GetComponent <Enemy>().TakeDamage(damage, hit.point); } else { objectPooler.SpawnFromPool("WallParticles", hit.point, Quaternion.Euler(new Vector3(0, hit.transform.position.y, 0)), objectPooler.pools[2]); } GameObject obj = objectPooler.SpawnFromPool("BulletTrail", muzzleTransform.position, Quaternion.identity, objectPooler.pools[3]); BulletTrail bulletTrail = obj.GetComponent <BulletTrail>(); bulletTrail.Initialize(muzzleTransform.position, hit.point); } else { Debug.DrawRay(muzzleTransform.position, muzzleTransform.forward * 1000, Color.white, 2f); } muzzleTransform.localEulerAngles = Vector3.zero; } }
public override void OnEffect(Ray2D ray, RaycastHit2D rayHit) { BulletTrail bulletTrail = storage.Find(obj => !obj.gameObject.activeInHierarchy); if (bulletTrail == null) { return; } GameObject gameObj = bulletTrail.gameObject; float angle = Mathf.Atan2(ray.direction.y, ray.direction.x) * Mathf.Rad2Deg; gameObj.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); gameObj.transform.position = ray.origin; gameObj.SetActive(true); StartCoroutine(DisableObject(gameObj, 3f)); }
void FireWeapon() { if (currentBarrelSpeed <= 2000) { currentBarrelSpeed += 30; } else { if (Time.time >= canShoot) { canShoot = Time.time + 1 / fireRate; audioSource.Play(); GunShake(); muzzle.SetActive(true); RaycastHit hit; if (Physics.Raycast(muzzleTransform.position, muzzleTransform.forward, out hit, Mathf.Infinity, layerMask)) { Debug.DrawRay(muzzleTransform.position, muzzleTransform.forward * hit.distance, Color.red, 2f); if (hit.transform.CompareTag("Enemy")) { hit.transform.GetComponent <Enemy>().TakeDamage(damage, hit.point); } else { objectPooler.SpawnFromPool("WallParticles", hit.point, Quaternion.Euler(new Vector3(0, hit.transform.position.y, 0)), objectPooler.pools[2]); } GameObject obj = objectPooler.SpawnFromPool("BulletTrail", muzzleTransform.position, Quaternion.identity, objectPooler.pools[3]); BulletTrail bulletTrail = obj.GetComponent <BulletTrail>(); bulletTrail.Initialize(muzzleTransform.position, hit.point); } else { Debug.DrawRay(muzzleTransform.position, muzzleTransform.forward * 1000, Color.white, 2f); } } } model.transform.Rotate(new Vector3(0, 0, currentBarrelSpeed * Time.deltaTime)); }
protected virtual void DrawBulletPath(Vector3 StartPos, Vector3 EndPos) { BulletTrail bt = Instantiate <BulletTrail>(Resources.Load <BulletTrail>("BulletTrail")); bt.SetupBulletTrail(StartPos, EndPos, 1f / RateOfFire); }
protected void AttachNewBulletTrail() { CurrentBulletTrail = BulletTrail.SpawnBulletTrail(this); }
protected sealed override void OnDeactivate() { CurrentBulletTrail = null; OnBulletDeactivate(); }