public void Update() { foreach (Entity e in LiveEntities) { e.Update(); } if (game.mouseInputHandler.IsLeftDown()) { testWeapon.Fire(); } testWeapon.Update(game.mouseInputHandler.GetRealMousePos()); int count = bullets.Count; for (int i = 0; i < count; i++) { Bullet b = bullets[i]; if (b.canDestroy) { bullets.Remove(bullets[i]); count--; i--; } b.Update(); } camera.SetPosition(player.GetOrigin()); }
private IEnumerator attack() { if (anim != null) { anim.SetTrigger("Attack"); } yield return(new WaitForSeconds(.08f)); if (weapon == null) { weapon = weaponController.currentWeapon as RangedWeapon; } //Apply a deviation to the aiming of the enemy Vector3 weaponRotOriginal = weapon.gameObject.transform.eulerAngles; Vector3 newWeaponRot = weaponRotOriginal + new Vector3(0f, Random.Range(-deviation, deviation), 0f); weapon.gameObject.transform.eulerAngles = newWeaponRot; weapon.Fire(); weapon.gameObject.transform.eulerAngles = weaponRotOriginal; lastAttackTime = Time.time; }
private void attack() { if (weapon == null) { weapon = weaponController.currentWeapon as RangedWeapon; } weapon.Fire(); }
void RangedAttack() { int max_length = ((Unit)unit.enemies_in_range[0]).GetSoldiers().Length - 1; int index = Random.Range(0, max_length); if (((Unit)unit.enemies_in_range[0]).GetSoldiers().Length > 0) { rangedWeapon.Fire(((Unit)unit.enemies_in_range[0]).GetSoldiers()[index], this.transform.position); } }
private void Update() { float angle = Mathf.Atan2(target.transform.position.y - transform.position.y, target.transform.position.x - transform.position.x) * Mathf.Rad2Deg - 90.0f; transform.rotation = Quaternion.Euler(0, 0, angle); if (Vector3.Distance(target.transform.position, transform.position) <= weapon.projectile.maxDistance) { weapon.Fire(); } }
private void HandleAttack() { if (!isJump && !isMoving) { if (Input.GetKey(KeyCode.W)) { Debug.Log(rangedWeapon.angle); if (rangedWeapon.angle < 90) { rangedWeapon.angle += 0.4f; } } else if (Input.GetKey(KeyCode.S)) { Debug.Log(rangedWeapon.angle); if (rangedWeapon.angle >= 0) { rangedWeapon.angle -= 0.4f; } } else if (Input.GetKey(KeyCode.Space)) { Debug.Log(rangedWeapon.power); if (rangedWeapon.power <= 50) { rangedWeapon.power += 0.4f; } else { rangedWeapon.Fire(); OnAttacked.Invoke(); } } else if (Input.GetKeyUp(KeyCode.Space)) { rangedWeapon.Fire(); OnAttacked.Invoke(); } } }
void Update() { if (Time.timeScale == 0) { return; } if (power.CurrentPower <= 0) { currentSpeed = slowSpeed; } else if (CurrentSpeed == Speed.NoPower || (CurrentSpeed == Speed.Boost && body.velocity.sqrMagnitude > 0 && !power.UsePower(boostPowerDrain * Time.deltaTime))) { currentSpeed = speed; } var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); float angle = Mathf.Atan2(mousePos.y - transform.position.y, mousePos.x - transform.position.x) * Mathf.Rad2Deg - 90.0f; body.rotation = angle; float moveHorizontal = Input.GetAxisRaw("Horizontal"); float moveVertical = Input.GetAxisRaw("Vertical"); if (GameManager.Instance.UseRelativeControls) { basisX = transform.up; basisY = transform.right; } var direction = moveVertical * basisX + moveHorizontal * basisY; direction.Normalize(); body.velocity = direction * currentSpeed; if (Input.GetButtonDown("Cancel")) { Time.timeScale = 0; pauseMenu.SetActive(true); return; } if (Input.GetButtonDown("Fire3")) { if (CurrentSpeed == Speed.Boost) { currentSpeed = speed; } else if (power.CurrentPower > 0) { currentSpeed = boostSpeed; } } if (Input.GetButtonDown("Jump")) { health.SetShield(!health.ShieldEnabled); } if (Input.GetButton("Fire1")) { weapon.Fire(); } }
protected override void OnStateUpdate(RangedAIState state) { switch (state) { case RangedAIState.Strafe: { Vector3 diff = AttackTarget.position - transform.position; Vector3 dir = diff; dir.y = 0f; float sqrDist = diff.sqrMagnitude; if (sqrDist > _strafeRange * _strafeRange) { // Move To Target Move(dir, _strafeSpeed); } else { // Request Attack if (_attackRequestElapsedCooldown < _attackRequestCooldown) { _attackRequestElapsedCooldown += Timer.Delta; if (_attackRequestElapsedCooldown >= _attackRequestCooldown) { AttackTarget.SendMessage("RequestAttack", gameObject); _attackRequestElapsedCooldown = 0f; } } // Random Strafe / Step Back if (_strafeElapsedCooldown < _strafeCooldown) { if (_isBackwards) { float range = Mathf.Min(_strafeRange, _dangerRange + 0.5f); if (sqrDist <= range * range) { Move(-dir, _strafeSpeed * 0.5f); } else { _isBackwards = false; } } else if (sqrDist > _dangerRange * _dangerRange) { _strafeElapsedCooldown += Timer.Delta; if (_strafeElapsedCooldown >= _strafeCooldown) { _strafeDir = Random.value > 0.5f ? 1f : -1f; _strafeElapsedTime = _strafeElapsedTime < _strafeTime ? _strafeTime - _strafeElapsedTime : 0f; _strafeElapsedCooldown = 0f; } if (_strafeElapsedTime < _strafeTime) { Vector3 moveDir = _strafeDir * (Quaternion.AngleAxis(75f, AttackTarget.up) * dir); Move(moveDir, _strafeSpeed); _strafeElapsedTime += Timer.Delta; } } else { _isBackwards = true; } } } Rotate(Quaternion.LookRotation(dir), _strafeRotateSpeed); Vector3 velocity = transform.InverseTransformVector(Velocity); Animator.SetFloat(AnimatorHash.VelocityX, Mathf.Min(velocity.x, _strafeSpeed), 0.1f, Timer.Delta); Animator.SetFloat(AnimatorHash.VelocityZ, Mathf.Min(velocity.z, _strafeSpeed), 0.1f, Timer.Delta); } break; case RangedAIState.Attack: { if (_weapon.IsShootable) { Animator.SetTrigger("Attack"); _weapon.Fire(); } else if (_weapon.CurrentAmmo == 0) { CurrentState = RangedAIState.Strafe; } Vector3 dir = AttackTarget.position - transform.position; dir.y = 0f; Rotate(Quaternion.LookRotation(dir), _attackRotateSpeed); Animator.SetFloat(AnimatorHash.VelocityX, 0f, 0.1f, Timer.Delta); Animator.SetFloat(AnimatorHash.VelocityZ, 0f, 0.1f, Timer.Delta); } break; } }