private void Update() { if (EnemyManager.EnemyContainerInstance != null && Level > 0 && Time.time - LastShoot > ArrowTime[Level]) { Transform shootLocation = (ShootLocations[UnityEngine.Random.Range(0, ShootLocations.Length)]); if (Mathf.Abs(EnemyManager.EnemyContainerInstance.transform.position.z - shootLocation.position.z) < ShootDistances[Level]) { Projectile projectile = ProjectilePool.Instance.GetProjectile(); Vector3 pos = EnemyManager.EnemyContainerInstance.transform.position + Vector3.right * UnityEngine.Random.Range(-5f, 5f); projectile.Shoot(shootLocation.position, pos); LastShoot = Time.time; } } if (RequiredBuilt == null) { return; } //Handle not building if previous building has not built! if (RequiredBuilt.Level == 0) { if (!_raddishShop.DisableShop) { _raddishShop.DisableShop = true; } } else if (!_levelingUp && _raddishShop.DisableShop) { _raddishShop.DisableShop = false; } }
public void Shoot(float angle) { AudioManager.instance.Play("DisparoTorreta"); Projectile projectile = ProjectilePool.Instance.GetObject(); projectile.Shoot(projectileSpawner.position, angle, bulletSpeed); }
/// <summary> /// Checks actor's inventory for projectile, then shoots it from actor's position /// </summary> /// <param name="actor">Actor</param> private void Shoot(Actor actor) { GameController.Log("Executing ShootCommand on " + actor.name, GameController.LogCommands); // Retrieve projectile from actor inventory projectile = GetProjectile(actor); if (projectile != null) { // Set bullet on player projectile.transform.position = actor.transform.position; // Get direction actor is facing (TODO: consider handling this for actors that don't rotate) BaseConstants.Direction direction = actor.GetComponent <MoveComponent>().currentDirection; GameController.Log("Projectile direction: " + direction.ToString(), GameController.LogCommands); // Send projectile in that direction Vector2 trajectory = DirectionHelper.DirectionToVector(direction); projectile.Shoot(trajectory, actor); } else { GameController.LogWarning("Primary Shoot Command: could not find projectile in actor " + actor.name + "'s inventory", GameController.LogCommands); } }
public void DrawGameObjects()//draw all Gameobjects into the gamedisplay { foreach (Invader invader in Invaders) { invader.Draw(); } foreach (Wall wall in Walls) { wall.Draw(); } foreach (Ufo ufo in Ufos) { ufo.Draw(); } foreach (PlayerProjectile playerprojectile in PlayerProjectiles) { playerprojectile.Draw(); playerprojectile.Shoot(); } foreach (EnemyProjectile Projectile in EnemyProjectiles) { Projectile.Draw(); Projectile.Shoot(); } Player.Draw(); }
public override void Step(Shooter p_shooter) { Projectile proj = SpawnProjectile(p_shooter); Vector2 target = FetchTarget(p_shooter, proj); Vector2 direction = (target - (Vector2)proj.transform.position).normalized; float angle = (float)p_shooter.GetPatternInfo(this, "angle"); bool reverse = (bool)p_shooter.GetPatternInfo(this, "reverse"); float angleStart = (float)p_shooter.GetPatternInfo(this, "angleStart"); direction = direction.Rotate(angle); proj.Shoot(p_shooter, target, direction); if (m_shots > 1) { float angleStep = m_angleRange / (m_shots / 2); angle += reverse ? -angleStep : angleStep; } if (angle >= angleStart + m_angleRange) { reverse = true; } if (angle <= angleStart) { reverse = false; } p_shooter.SetPatternInfo(this, "angle", angle); p_shooter.SetPatternInfo(this, "reverse", reverse); }
public override bool Attack(DirectionVector direction) { if (_shootTimer == null) { _shootTimer = new ExpirationTimer(_skillSet.ShootDeltaTime); _shootTimer.OnExpiredTimer += AttackAction; } if (_shootTimer.ExpirationTime != _skillSet.ShootDeltaTime) { _shootTimer.ExpirationTime = _skillSet.ShootDeltaTime; } if (_isCanAttack) { Projectile projectile = ObjectsAPI.SpawnObject(_projectile.gameObject).GetComponent <Projectile>(); float rotation = direction.Value.VectorAngle(); float projectileSpeed = _skillSet.ProjectileSpeed; projectile.Shoot(transform.position, rotation, 1, direction.Value * projectileSpeed, _damageSkill.DamageValue, _classInformation.CurrentFraction); _isCanAttack = false; _shootTimer.Start(); return(true); } return(false); }
public virtual void Shoot() { float forceCharge = this.forceCharge - this.forceCharge % forceChargeGrounding; projectile.Shoot(shootForce * forceCharge * transform.forward, shootTorque * torqueCharge); projectile = null; }
void LaunchBullet() { if (currProjectile == null) { return; } ++shootedProjectiles; currProjectile.transform.SetParent(null); //if (isPlayerWeapon) { // Vector3 mousePos = GameManager.Instance.mouse.mousePosWorld - shootPos[currShootPos].position; // float mouseRot = (Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg + 270) % 360; // if (Mathf.Abs(mouseRot - transform.rotation.eulerAngles.z) <= 60) // currProjectile.transform.rotation = Quaternion.Euler(0, 0, mouseRot); //} //else if (isAutoTargetPlayer) { // if (GameManager.Instance.player != null) // currProjectile.transform.rotation = Quaternion.LookRotation(Vector3.forward, GameManager.Instance.player.transform.position - transform.position); //} currProjectile.transform.rotation = transform.rotation; currProjectile.Shoot(parentPb.velocity); AudioManager.Instance.Play(shootClip); if (++currShootPos >= shootPos.Length) { currShootPos = 0; } currProjectile = null; }
public void ShootProjectile(Vector2 angle) { float eulerAngleToShootAt = Vector2.SignedAngle(Vector2.up, angle.normalized); GameObject newProjectileGameObject = Instantiate(projectilePrefab, trans.position, Quaternion.Euler(0, 0, eulerAngleToShootAt)); Projectile newProjectile = newProjectileGameObject.GetComponent <Projectile>(); newProjectile.Shoot(angle); }
// public void Attack() // { // int dmg = damageScale; // //calculate attack data : damage, location, number of damage points ("projectiles") etc... // //send relevant data : damage, damage points (locations relative to cursor) etc... as param to crossHairScript's // // sendAttack() method. // // //use variables to calculate the actual damaged passed to the world and where the damage // //hits in world space // //use collision component of the cursor to manupulate the extent of damage for damage spread/choke // //example of this would be a shotgun or an explosive ot even a melee weapon with swing. // //this.transform.localPosition = new Vector3(5,2,2); // // //crosshairScript.sendAttack (dmg[], dmgLocations[]); // crosshairScript.sendAttack(dmg); // } /** * Description: Calculates relevant data to be passed on to a newly created gameObject's projectile script to handle * collision and pathing logic. */ public void Attack(Vector2 direction) { //calc attack damage to be delivered via the projectile prefab/script Projectile projectile = (Projectile)Instantiate(this.projectile, this.transform.position, this.transform.rotation); projectile.Init(fixedDmg, range); projectile.Shoot(direction, speed); }
private void ShootProjectile() { if (!EnemyProjectile.Active) { EnemyProjectile.Shoot(Position, GoingRight); ChangeAnimationState(Animation_State.throwing); LockAnimation(Animations[ActiveAnimation]); } }
private void CreateProjectile() { //Add verification if we add ammo audioSource.PlayOneShot(shootSound); Projectile newProjectile = Instantiate(bulletPrefab, transform.position, transform.rotation, projectileFolder.transform); newProjectile.GetComponent <DamageDealer>().Damage = weapon.damage; newProjectile.Shoot(gameObject); }
protected override void Fire(Vector2 Pos) { for (int i = 0; i < Shots; i++) { Projectile P = Instantiate(Projectile); ProjectileData D = ProjectileData.Clone(); D.Impulse += Random.Range(-Mathf.Min(D.Impulse / 2, ForceSpread), ForceSpread); P.Shoot(Holder, (Pos + Random.insideUnitCircle * Spread) - (Vector2)transform.position, D); } }
private void SpawnProjectile() { GameObject spawnedProjectile = GameObject.Instantiate(projectilePrefab , projectileSpawnPoint.transform.position , projectileSpawnPoint.transform.rotation); Projectile projectile = spawnedProjectile.AddComponent <Projectile>(); projectile.Init(projectileSpawnPoint.transform.forward); projectile.Shoot(); }
private void Shoot() { if (AmmoHandler.ammo > 0 && P_PlayerInteractionEnabled == true) { p_Projectile = Instantiate(p_ProjectilePrefab, p_ProjectileOrigin.position, Quaternion.identity); p_Projectile.Shoot(m_Direction, p_ShootForce, "Enemy"); AmmoHandler.DecrementAmmo(1); } }
private void Shoot() { if (ammo != null) { ammo.ActivateProjectile(); ammo.Shoot(direction, force); ammo = null; } vector.StopVectorAnimation(); }
public override void Fire() { Projectile p = Instantiate(projectilePrefab, transform.position, Quaternion.Euler(0, 0, transform.eulerAngles.z - 90f)) as Projectile; float w = drawStringK * (Mathf.Sqrt(Mathf.Pow(base.DrawPercent() * drawStringLengthX, 2f) + Mathf.Pow(drawStringLengthY, 2f)) - drawStringLengthY); p.Shoot(w, -transform.right); base.Fire(); }
void Shoot() { GameObject bullet = Instantiate(projectile, rigidbody2.position + Vector2.up * 0.5f, Quaternion.identity); Projectile cog = bullet.GetComponent <Projectile>(); cog.Shoot(direction, shootSpeed); PlaySound(shoot); anim.SetTrigger("Launch"); }
// Update is called once per frame void Update() { _deltaTimeJump += Time.deltaTime; _deltaTimeAttack += Time.deltaTime; _moviment = new Vector2(Input.GetAxisRaw("Horizontal") * speedForce, 0.0f); _jump = Input.GetButtonDown("Jump") ? new Vector2(_body.velocity.x, 1 * jumpForce) : new Vector2(_body.velocity.x, 0 * jumpForce); if (_moviment.sqrMagnitude > 0.1f) { isRightFaced = (Input.GetAxis("Horizontal") > 0.0f); _renderer.flipX = !(Input.GetAxis("Horizontal") > 0.0f); } if (Input.GetButtonDown("Jump") && IsGrounded) { _body.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse); IsDoubleJumpReady = true; } if (Input.GetButtonDown("Jump") && !IsGrounded && _deltaTimeJump > targetTimeJump && IsDoubleJumpReady) { if (_body.velocity.y < 0f) { _body.AddForce(new Vector2(0.0f, -_body.velocity.y) - _body.velocity, ForceMode2D.Impulse); } _deltaTimeJump = 0; _body.AddForce(_jump - _body.velocity, ForceMode2D.Impulse); IsDoubleJumpReady = false; } if (Input.GetButtonDown("Fire1") && _deltaTimeAttack > targetTimeAttack) { isAttacking = true; float faceFactor = (isRightFaced ? 1.0f : -1.0f); Vector3 projectileOffsetValue = new Vector3(projectileOffset.x * faceFactor, 0, 0); Vector3 projectilePosition = this.transform.position + projectileOffsetValue; Projectile projectile = ObjectPooling.GetProjectile(); projectile.transform.position = projectilePosition; projectile.Shoot(isRightFaced); _deltaTimeAttack = 0; } else { isAttacking = false; } _animator.SetFloat(speedParam, Mathf.Abs(_body.velocity.x)); _animator.SetFloat(YParam, _body.velocity.y); _animator.SetBool(groundedParam, IsGrounded); _animator.SetBool(isFiring, isAttacking); }
public void Shoot(InputAction.CallbackContext _context) { if (!_context.performed) { return; } Projectile _proj = projectilePool.GetComponent(); _proj.transform.position = shotSocket.transform.position; _proj.Shoot(shotSocket.transform.forward * shootForce); }
public void Shoot() { Projectile projectile = ProjectileManager.RequestProjectile(); projectile.gameObject.SetActive(true); projectile.transform.rotation = Tank.transform.rotation; projectile.Shoot(this); CurrentAmmo--; curCooldown = stats.ShotCooldown; OnShotFired?.Invoke(); }
void CheckShoot() { if (!ShootingAvailable()) { return; } Projectile projectile = Instantiate(projectilePrefab); projectile.transform.SetParent(this.transform); projectile.Shoot(this, Vector2.up); //turn this around }
private IEnumerator Attack(Player player) { myEnemyController.IsAttacking = true; myAnimtor.SetBool(myEnemyController.attackingBool, true); Projectile currentProjectile = Instantiate(projectile, barrel.position, Quaternion.identity).GetComponent <Projectile>(); currentProjectile.Shoot(player.transform.position); yield return(new WaitForSeconds(1 / attackSpeed)); myEnemyController.IsAttacking = false; myAnimtor.SetBool(myEnemyController.attackingBool, false); }
public void Shoot() { GameObject obj = Instantiate(skillObj[0], p.spawn.position, Quaternion.identity); Projectile proj = obj.GetComponent <Projectile>(); proj.pN = p.playerNumber; proj.Shoot(transform.rotation, 825); proj.attack = 10; FMODUnity.RuntimeManager.PlayOneShot(FMODPaths.THROW_SFX, GetComponent <Transform>().position); p.anim.SetTrigger("Attacks"); }
public override void Use(object o) { Actor shooter = null; try{ shooter = (Actor)o; } catch (Exception e) { Debug.LogError("The shooter is null"); return; } if (shooter == null) { return; } if (loadedMagazine) { if (chamberedProjectile) { chamberedProjectile.Shoot(transform.up, shooter); } else { Chamber(loadedMagazine.Cycle(this)); if (chamberedProjectile) { chamberedProjectile.Shoot(transform.up, shooter); FireEffects(); } } } else { Debug.Log("There is no loaded Magazine"); } }
public void HandleShoot() { if (currentInterval >= fireRate) { float angle = SpreadAngle / 180f; Vector3 spreadDirection = Vector3.Slerp(Muzzle.forward, Random.insideUnitSphere, angle); Projectile projectile = Instantiate(ProjectilePrefab, Muzzle.position, Quaternion.LookRotation(spreadDirection)); projectile.Shoot(bulletSpeed, impulse); currentInterval = 0; } currentInterval += Time.deltaTime; }
public virtual Projectile Shoot(Vector3 position, Vector3 forward, Vector3 upward) { Projectile projectile = null; if (projectilePrefab != null) { initProjectilesIfNeeded(); projectile = projectiles.Dequeue(); projectile.Shoot(position, forward, upward); projectiles.Enqueue(projectile); } return(projectile); }
protected virtual void Shoot() { if (Time.time > shootTimer) { shootTimer = Time.time + fireDelay; Projectile pro = Instantiate(projectilePrefab, muzzlePosition.position, muzzlePosition.rotation * CalculateSpread()); pro.Shoot(bulletSpeed, bulletDamage); this.transform.localPosition += kickBack; IncreaseInaccuracy(inaccuracyPerShot); ApplyInaccuracy(); } }
private IEnumerator Shoot() { isShooting = true; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { Projectile currentProjectile = Instantiate(projectile, transform.position, Quaternion.identity).GetComponent <Projectile>(); currentProjectile.Shoot(hit.point); } yield return(new WaitForSeconds(1.0f / speed)); isShooting = false; }
public void ThrowArrow() { if (!arrowInstance) { return; } EventTrigger attackEvent = new CustomEvent(agent.aimerPivot.position, EventSubject.Attack, GameConfig.projectilePriority); // TODO : fix the direction calculation, the base position should be the head of the character, or the end of the arrow, not the agent Vector3 shootDirection = agent.arrowParent.position - agent.aimerPivot.position; arrowInstance.Shoot(attackEvent, shootDirection.normalized * agent.shootForce); arrowInstance.transform.SetParent(null); arrowInstance = null; }
private void spawnProjectile() { if (attackSound) { AudioSource.PlayClipAtPoint(attackSound, transform.position); } dir = new Vector3(targetPos.x - transform.position.x, 0, 0); distL = (transform.position - targetPos - left).magnitude; distR = (transform.position - targetPos - right).magnitude; toLeft = (attackRange + distL) <= distR; bool facing = distL <= distR; short faceDir; if (facing) faceDir = -1; else faceDir = 1; shot = Instantiate(shotObj, transform.position + faceDir * xhalf, transform.rotation) as Projectile; shot.Shoot(dir.normalized); }
// Update is called once per frame void Update() { foreach (GameObject enem in enemies) { tempDist = (transform.position - enem.transform.position).magnitude; if (tempDist < distance) { distance = tempDist; dir = (transform.position - enem.transform.position).normalized; } } if (enemies.Count < 1) { somethingToAttack = false; } else { somethingToAttack = true; } if(somethingToAttack) { if(shot_CD >= 2) { shot = Instantiate(shotObj, transform.position, transform.rotation) as Projectile; shot.Shoot(-dir); shot_CD = 0; } } shot_CD += Time.deltaTime; }
private void boltAttack() { //animation //bolt bolt = Instantiate(boltObj, transform.position, transform.rotation) as Projectile; bolt.setStun(bolt_Stun); //Debug.Log(direction); findPos(); bolt.Shoot(0, direction / 1.5f); bolt_CD = 0; }
public void ballAttack() { ball = Instantiate(ballObj, transform.position, transform.rotation) as Projectile; ball.Shoot(0, direction * 0.7f); fireBall_CD = 0; iceBall_CD = 0; }