public static Color GetStateColor(TurretState state) { Color color = Color.white; switch (state) { case TurretState.FULL: color = Color.white; break; case TurretState.SLIGHTLY_DAMAGED: color = new Color(253, 255, 184); break; case TurretState.DAMAGED: color = Color.yellow; break; case TurretState.MORE_DAMAGED: color = new Color(255, 136, 0); break; case TurretState.HEAVILY_DAMAGED: color = Color.red; break; case TurretState.DESTROYED: color = Color.grey; break; } return color; }
public void getTurretState() { if (currentTurretState == TurretState.ATTACK) { //10% under fiendens energi if (this.Energy + ((this.Energy / 100) * 10) < eData.Energy) currentTurretState= TurretState.SAVEENERGY; else if (!isOnTarget) currentTurretState= TurretState.SCAN; } else if (currentTurretState == TurretState.SAVEENERGY) { // har mer energi if (this.Energy > eData.Energy) currentTurretState= TurretState.ATTACK; else if (!isOnTarget) currentTurretState= TurretState.SCAN; } else if (currentTurretState == TurretState.SCAN) { if (isOnTarget) { if (this.Energy + (this.Energy / 100) * 10 < eData.Energy) currentTurretState= TurretState.SAVEENERGY; else currentTurretState= TurretState.ATTACK; } } }
public AbstractTurret(int maxHealth, int attackDamage, float cooldown, int row, int column, float fireRate, int shotAmount, AreaOfEffect areaOfEffect, TurretState turretState) : base(maxHealth, attackDamage, cooldown, row, column) { FireRate = fireRate; maximumAmmo = shotAmount; CurrentAmmo = shotAmount; Cost = cost; this.areaOfEffect = areaOfEffect; this.turretState = turretState; }
public void ChangeTurretState(TurretState myTurretState) { switch (myTurretState) { case TurretState.active: break; case TurretState.spooking: break; case TurretState.recharging: break; } }
void firingState() { //Initialize the state if I'm just now entering. if (currentState != TurretState.FIRING) { framesInState = 0; timeInState = 0.0f; if (debugMode) { Debug.Log("Entered firing State"); } currentState = TurretState.FIRING; return; } else { cSlice.shoot(projectile, barrel.gameObject.transform.position, barrel.gameObject.transform.forward, barrel.gameObject.transform.rotation, false); coolingState(); return; } }
void setState() { if (closeSomthing || dr.PlayerGetInSide || playOnce[4]) // 플레이어가 트리거 안으로 들어오면 무조건 디펜스 모드임 수색함 { if (nearSomthing == null) { nearSomthing = dr.EnterThing; } TS = TurretState.DefenceMode; if (ctrlCorutain) { PlaySound("turret_CentreMode_Activated"); } } else { timer[1] += Time.deltaTime; if (timer[1] > 10f) { timer[1] = 0f; } if (!closeSomthing && !dr.PlayerGetInSide) { TS = TurretState.Working; if (!isDetectTarget) { PlaySound("turret_retire_1"); } } } if (isDetectTarget) { Head.transform.DOKill(); TS = TurretState.FindedTarget; } }
//Main turret behaviour states, can be overriden in inherited members to perform customizable function public virtual void TurretStates() { switch (turretState) { //Searching state case TurretState.searching: if (targets.Count != 0) { LookAtTarget(); if (CurrentTarget) { //Debug.Log("Target Acquired"); Vector3 Dir = (CurrentTarget.transform.position - barrel.transform.position); float angle = Vector3.Angle(Dir, barrel.transform.forward); //Debug.Log("angle is " + angle); if (angle <= 5) { turretState = TurretState.firingtarget; } } } else { //Debug.Log("Searching for target"); CurrentTarget = null; SearchTarget(); } break; case TurretState.firingtarget: //Debug.Log("Firing Target"); FireAtTarget(); //StartCoroutine(Countdown(1f)); break; } }
/// <summary> /// /// </summary> /// <param name="target"></param> /// <param name="_fireNum"></param> public override void SetEnemy(Vector3 targetPosition, int _fireNum = 1) { if (gun == null) { return; } // 获取朝向向量 Vector3 rot = Quaternion.LookRotation(targetPosition - gun.position).eulerAngles; turretRollTarget = rot.y; gunRollTarget = rot.x; isTurretMove = true; isGunMove = true; enemyPos = targetPosition; if (currentTurState == TurretState.Fire) { StopCoroutine("AttackIE"); // 停止当前的开火 } fireNum = _fireNum; currentTurState = TurretState.AimAt; }
/// <summary> /// 初始化炮弹 /// </summary> /// <param name="_fireNum">弹药发射轮数</param> /// <returns></returns> IEnumerator AttackIE(int _fireNum) { if (ammunition == null) { StopCoroutine("AttackIE"); yield return(null); } for (int i = 0; i < _fireNum; i++) { for (int j = 0; j < launch.Length; j++) { InitFirePower(launch[j], ammunition); yield return(new WaitForSeconds(0.2f)); } yield return(new WaitForSeconds(2)); } enemy = null; currentTurState = TurretState.Reset; ResetState(); yield return(null); }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { // set enemy sprites this.animator = animator; sp = animator.GetComponent <TurretSP> (); state = animator.GetComponentInChildren <TurretState> (); if (lineUpdate) { lineUpdate.EnableLine(); } if (shoot) { shoot.StopShoot(); UpdateTargetPos(); } shooting = false; sp.SetEnemySprite(); state.SetTargetsToPlayer(); }
public void Update(List <Enemy> enemies, GameTime gameTime) { deltaTime = (float)(gameTime.ElapsedGameTime.TotalSeconds); fireRate += deltaTime; counter1++; if (counter1 > 10) { counter1 = 0; pickTarget(enemies); } if (target != null && target.Active) { SetAngle((int)target.Position.X, (int)target.Position.Y); if (fireRate >= 0.25f) { fireRate = 0f; target.TakeDamage(2); //Bullet b = bullets.Dequeue(); //Shoot(target, b); //bullets.Enqueue(b); } turretState = TurretState.firing; } else { turretState = TurretState.idle; } }
// Update is called once per frame private void Update() { if (m_dead) { // Wait until sounds have stopped playing then kill if (!m_audioSource.isPlaying) { Destroy(this.gameObject); } return; } // As soon as we enter the frame, start the lock-on sequence if (!m_lockIndicatorHelper.lockIndicator.IsActive() && m_lockIndicatorHelper.InViewFrustum(m_boxCollider.bounds)) { //m_lockIndicatorHelper.lockIndicator.StartLockOnSequence(); } // Animate turret Vector3 toPlayer = Camera.main.transform.position - transform.position; toPlayer.y = 0; // we only care about distance along ground plane float distanceToPlayer = Vector3.Magnitude(toPlayer); float now = Time.time; float delta = now - m_t0; switch (m_state) { default: break; case TurretState.ScanningSleep: if (distanceToPlayer <= playerTrackingDistance) { m_state = TurretState.TrackingStart; } else if (now >= m_t1) { Vector3 old_angles = m_turret.localRotation.eulerAngles; Vector3 new_angles = old_angles; new_angles.y = m_angles[Random.Range(0, m_angles.Length)]; m_turretStartRotation = m_turret.localRotation; m_turretEndRotation = Quaternion.Euler(new_angles); m_t0 = now; m_t1 = now + Mathf.Abs(new_angles.y - old_angles.y) / turretScanSpeed; m_state = TurretState.ScanningSweep; } break; case TurretState.ScanningSweep: if (distanceToPlayer <= playerTrackingDistance) { m_state = TurretState.TrackingStart; } else if (now < m_t1) { m_turret.localRotation = Quaternion.Slerp(m_turretStartRotation, m_turretEndRotation, delta / (m_t1 - m_t0)); } else { m_t0 = now; m_t1 = now + 2; m_state = TurretState.ScanningSleep; } break; case TurretState.TrackingStart: if (distanceToPlayer > playerTrackingDistance) { m_state = TurretState.TrackingEnd; m_gunStartRotation = m_gun.localRotation; m_gunEndRotation = m_gunZeroRotation; m_t0 = now; m_t1 = now + 2; } else { /* * Player position is transformed to turret-local space and then the * direction to rotate at the tracking speed is determined using a * cross product. * * We compare two vectors: turret aim direction and player in local * YZ (X is the axis we rotate the turret about in its local space). * The cross product produces a vector along X and the magnitude is: * |aimVector|*|playerLocalYZ|*sin(angle) = 1*1*sin(angle) = * sin(angle). */ Vector3 playerLocalPos = m_turret.transform.InverseTransformPoint(Camera.main.transform.position); Vector3 playerLocalYZ = Vector3.Normalize(new Vector3(0, playerLocalPos.y, playerLocalPos.z)); Vector3 aimVector = Vector3.forward; // direction turret is pointing float sinAngle = Vector3.Cross(aimVector, playerLocalYZ).x; float direction = Mathf.Sign(sinAngle); if (Mathf.Abs(sinAngle) > Mathf.Sin(2 * Mathf.Deg2Rad)) { m_turret.Rotate(direction * Time.deltaTime * turretTrackingSpeed, 0, 0); } else { // Raise gun Vector3 targetAngles = m_gun.localRotation.eulerAngles; targetAngles.z = maxGunAngle; // bone -- and gun -- axis is along x, so rotate about z Quaternion targetElevation = Quaternion.Euler(targetAngles); Vector3 currentGunVector = m_gun.localRotation * Vector3.right; Vector3 targetGunVector = targetElevation * Vector3.right; float angleToTarget = Mathf.Abs(Vector3.Angle(currentGunVector, targetGunVector)); float time = angleToTarget / turretScanSpeed; m_gun.localRotation = Quaternion.Lerp(m_gun.localRotation, targetElevation, Time.deltaTime / time); } } break; case TurretState.TrackingEnd: // Lower gun then return to scanning if (now < m_t1) { m_gun.localRotation = Quaternion.Lerp(m_gunStartRotation, m_gunEndRotation, delta / (m_t1 - m_t0)); } else { m_t1 = now + 1; m_state = TurretState.ScanningSleep; } break; } }
public void Heal(float amount) { this.Health = this.Health + amount; state = TurretStateManager.GetState(health); if (objSprite == null) return; objSprite.color = TurretStateManager.GetStateColor(state); }
public void TakeDamage(float amount) { //Debug.Log("TurretBarrelController:TakeDamage() - amount = " + amount); health -= amount; health = Mathf.Clamp(health, 0.0f, maxHealth); state = TurretStateManager.GetState(health); if (objSprite == null) return; objSprite.color = TurretStateManager.GetStateColor(state); GameInfoManager.Instance.IncrementDamageReceived(amount); }
void FSM() { switch (m_curTurretState) { case TurretState.idle: break; case TurretState.aiming: aimer.LookAt(m_target); float targetY = aimer.localEulerAngles.y; if (Mathf.Abs(transform.localEulerAngles.z - targetY) > 5f) { transform.Rotate(Vector3.forward, rotateSpeed * Time.deltaTime * m_rotateDir); } else { transform.localEulerAngles = new Vector3(0, 0, targetY); m_curTurretState = TurretState.attacking; } break; case TurretState.attacking: if (!m_target) { m_curTurretState = TurretState.idle; return; } if (m_canFire) { GameObject go = Instantiate(projectile, projectilePos[m_curBarrelIndex].position, projectilePos[m_curBarrelIndex].rotation) as GameObject; Rigidbody body = go.GetComponent <Rigidbody>(); body.velocity = go.transform.forward * muzzleSpeed; m_canFire = false; m_curBarrelShot--; if (m_curBarrelShot == 0) { m_curBarrelIndex++; m_curBarrelShot = shotPerBarrel; if (m_curBarrelIndex >= projectilePos.Length) { m_curBarrelIndex = 0; } } if (m_curMagAmmo > 0) { m_curMagAmmo--; if (m_curMagAmmo == 0) { m_curTurretState = TurretState.reloading; m_timer = 0f; } } } else { if (m_timer < fireInterval) { m_timer += Time.deltaTime; // Adjust shoot angle aimer.LookAt(m_target); float targetPosY = aimer.localEulerAngles.y; if (Mathf.Abs(transform.localEulerAngles.z - targetPosY) > 5f) { transform.Rotate(Vector3.forward, rotateSpeed * Time.deltaTime * m_rotateDir); } else { transform.localEulerAngles = new Vector3(0, 0, targetPosY); m_curTurretState = TurretState.attacking; } } else { m_timer = 0f; m_canFire = true; } } break; case TurretState.reloading: if (m_timer < reloadTime) { m_timer += Time.deltaTime; } else { m_timer = 0f; if (m_curMagCount > 0) { m_curMagCount--; m_curMagAmmo = magazineSize; m_curTurretState = TurretState.aiming; m_canFire = true; m_curBarrelIndex = 0; m_curBarrelShot = shotPerBarrel; } else if (m_curMagCount == -1) { m_curMagAmmo = magazineSize; m_curTurretState = TurretState.aiming; m_canFire = true; m_curBarrelIndex = 0; m_curBarrelShot = shotPerBarrel; } else { m_curTurretState = TurretState.idle; } } break; } }
// Update is called once per frame void Update() { RailgunTurretSFX.volume = PlayerPrefs.GetFloat("SFXVolume", 0.2f); if (target && !target.IsDead) { //aim at the target AimAtTarget(); } switch (currentTurretState) { //the turret is neither charging up, nor firing, it is just there doing nothing, looking at the enemy (if there's one) case TurretState.Idle: //move on to next state if there is a target and we have waited long enough if (target && waitTimeCountdown <= 0) { //begin charging up! currentTurretState = TurretState.ChargingUp; //reset charging up duration chargingCountdown = chargingDuration; //set the trigger of the animator turretAnimator.SetTrigger("Charge"); Debug.Log(currentTurretState.ToString()); } else if (waitTimeCountdown > 0) { //countdown waitTimeCountdown -= Time.deltaTime; } break; //the turret is currently charging up a shot case TurretState.ChargingUp: //start the charging countdown chargingCountdown -= Time.deltaTime; if (chargingCountdown <= 0) { //reset the charging countdown chargingCountdown = chargingDuration; //move on to the firing state currentTurretState = TurretState.Firing; Debug.Log(currentTurretState.ToString()); } break; case TurretState.Firing: /** * //start the firing countdown * firingCountdown -= Time.deltaTime; * * if (firingCountdown > 0) * { * //our railgun beam will be able to damage enemies * beam.canDamageEnemies = true; * } * else * { * //stop firing and go back to idle state * currentTurretState = TurretState.Idle; * * //reset the firing countdown * firingCountdown = firingDuration; * * //set a cooldown time before it can charge up and fire again * waitTimeCountdown = waitTimeBeforeCharging; * * //our railgun beam will not be able to damage enemies * beam.canDamageEnemies = false; * * } */ //fire the railgun bullet FireRailgunBullet(); //damage all enemies caught in the bullet foreach (EnemyController enemy in GetEnemiesInBeam()) { if (enemy) { enemy.Damage(damage); } } //go back to idle currentTurretState = TurretState.Idle; Debug.Log(currentTurretState.ToString()); //reset wait duration waitTimeCountdown = waitTimeBeforeCharging; break; } }
/* * * --------------------------------------------------------------------------------- * Targeting State * */ void targetingState() { if (currentState != TurretState.TARGETING) { framesInState = 0; timeInState = 0.0f; if (debugMode) { Debug.Log("Entered targeting State"); } currentState = TurretState.TARGETING; target = null; } else { framesInState++; timeInState += Time.smoothDeltaTime; bool noTargets = true; foreach (Potential p in potentials) { try { p.distance = (p.player.transform.position - this.transform.position).sqrMagnitude; if (p.distance < targetingRange * targetingRange) { p.inRange = true; p.lastTimeSeen = Time.time; p.timeInRange += Time.deltaTime; noTargets = false; } else { p.inRange = false; } } catch (System.Exception e) { e.ToString(); } } if (noTargets && timeInState > coolingTime) { waitingState(); } else if (noTargets) { wanderTurret(); } else { foreach (Potential p in potentials) { if (p.inRange) { if (target == null) { target = p; } else if (p.timeInRange * UnityEngine.Random.Range(0f, 1f) > target.timeInRange * UnityEngine.Random.Range(0f, 1f)) { target = p; } } } turningState(); } } }
void Update() { // Seek for detection if (state == TurretState.InRadarSeek && enableSeekTarget) { target = radar.GetTarget(cachedTransform, faction, true); // Target is found if (target != null) { targetOldPosition = target.transform.position; state = TurretState.InAcquisition; velocitySum = Vector3.zero; frameCount = 1; } // Reset target position else { float localHubYawAngle = hub.localEulerAngles.y > 180?hub.localEulerAngles.y - 360:hub.localEulerAngles.y; float localAxisAngle = axis.localEulerAngles.x > 180?axis.localEulerAngles.x - 360:axis.localEulerAngles.x; // Yaw if (hubRotation) { if (Mathf.Abs(localHubYawAngle) > speed * Time.deltaTime) { if (localHubYawAngle < 0) { hub.Rotate(Vector3.up * speed * Time.deltaTime, Space.Self); } else { hub.Rotate(Vector3.up * -speed * Time.deltaTime, Space.Self); } } } // Ptich if (axisRotation) { if (Mathf.Abs(localAxisAngle) > speed * Time.deltaTime) { if (localAxisAngle < 0) { axis.Rotate(Vector3.left * -speed * Time.deltaTime, Space.Self); } else { axis.Rotate(Vector3.left * speed * Time.deltaTime, Space.Self); } } } } } // Reach & track if (state != TurretState.InRadarSeek) { float distance = 0; // Target visible if (radar.fov.IsVisble(cachedTransform, target, out distance)) { float advance = 0; if (weaponSpeed > 0) { advance = (distance / weaponSpeed); } // Target + velocity in range Vector3 targetLookAt = target.transform.position + targetVelocity * advance; if (radar.fov.InFov(cachedTransform, targetLookAt, out distance)) { // In reach if (state == TurretState.InAcquisition) { Vector2 globalAngle = MathH.GetDeltaAngle(cachedTransform, targetLookAt, axis.localPosition); float localHubYawAngle = hub.localEulerAngles.y > 180?hub.localEulerAngles.y - 360:hub.localEulerAngles.y; float localAxisAngle = axis.localEulerAngles.x > 180?axis.localEulerAngles.x - 360:axis.localEulerAngles.x; // Yaw bool lockYaw = false; if (hubRotation) { if (Mathf.Abs(globalAngle.y - localHubYawAngle) > speed * Time.deltaTime) { if (localHubYawAngle < globalAngle.y) { hub.Rotate(Vector3.up * speed * Time.deltaTime, Space.Self); } else { hub.Rotate(Vector3.up * -speed * Time.deltaTime, Space.Self); } } else { lockYaw = true; } } else { lockYaw = true; } // Ptich bool lockPitch = false; if (axisRotation) { if (Mathf.Abs(globalAngle.x - localAxisAngle) > speed * Time.deltaTime) { if (localAxisAngle < globalAngle.x) { axis.Rotate(Vector3.left * -speed * Time.deltaTime, Space.Self); } else { axis.Rotate(Vector3.left * speed * Time.deltaTime, Space.Self); } } else { lockPitch = true; } } else { lockPitch = true; } if (lockPitch && lockYaw) { state = TurretState.InPursue; } } // In track else { if (hubRotation) { hub.LookAt(targetLookAt); hub.localRotation = Quaternion.Euler(new Vector3(0, hub.localRotation.eulerAngles.y, 0)); } if (axisRotation) { axis.LookAt(targetLookAt); axis.localRotation = Quaternion.Euler(new Vector3(axis.localRotation.eulerAngles.x, 0, 0)); } launcher.Shoot(target); } } else { launcher.StopShoot(); state = TurretState.InRadarSeek; //targetOldPosition = Vector3.zero; } } else { launcher.StopShoot(); state = TurretState.InRadarSeek; //targetOldPosition = Vector3.zero; } } }
// Use this for initialization public virtual void Start() { playerGameObjects = new ArrayList(); currentTurretState = TurretState.Idle; }
protected override void BaseFixedUpdate() { float dist = Vector3.Distance(DroidManager.Instance.playerTarget.transform.position, this.transform.position); switch (state) { case TurretState.Idle: if (dist < visionRange) { state = TurretState.IdleShooting; attackPoint = DroidManager.Instance.playerTarget; } break; case TurretState.IdleShooting: //look at if (dist < maxRange) { this.transform.LookAt(DroidManager.Instance.playerTarget.transform.position); if (currentAmno > 0) { muzzle.Play(); if (!HitWall() && accuracy - (dist / 100.0f) > Random.Range(0.0f, 1.0f)) { DroidManager.Instance.playerTarget.OnDamage(attackDamage); } currentAmno--; state = TurretState.Recoil; reloadTimer += recoilRate; } else { reloadTimer += reloadRate; state = TurretState.Reloading; } } else { state = TurretState.Idle; } break; case TurretState.TargetedShooting: //look at if (dist < maxRange) { this.transform.LookAt(DroidManager.Instance.playerTarget.transform.position); if (currentAmno > 0) { muzzle.Play(); if (!HitWall() && accuracy - (dist / 100.0f) > Random.Range(0.0f, 1.0f)) { DroidManager.Instance.playerTarget.OnDamage(attackDamage); } currentAmno--; state = TurretState.Recoil; reloadTimer += recoilRate; } else { reloadTimer += reloadRate; state = TurretState.Reloading; } } else { state = TurretState.Idle; } break; case TurretState.Recoil: //look at this.transform.LookAt(DroidManager.Instance.playerTarget.transform.position); if (reloadTimer <= 0.0f) { state = TurretState.IdleShooting; } break; case TurretState.Reloading: if (reloadTimer <= 0.0f) { currentAmno = 10; state = TurretState.Idle; } break; } }
public void putToOverload() { state = TurretState.onOverload; }
void Start() { turretState = TurretState.LockingOn; }
public void Reload() { reloadTimer += reloadRate; state = TurretState.Reloading; }
public void ChangingTurretState(TurretState _newState) { ExitTurretState(); turretState = _newState; EnterTurretState(); }
void Update() { if (!m_health.IsAlive()) { m_state = TurretState.IDLE; } switch (m_state) { case TurretState.IDLE: Vector3 topDir = Vector3.RotateTowards(top.transform.forward, idleTopTarget, idleTopSpeed * Mathf.Deg2Rad * Time.deltaTime, 0f); top.transform.rotation = Quaternion.LookRotation(topDir, Vector3.up); Vector3 barrelAngles = barrel.transform.localEulerAngles; float newAngle = barrelAngles.x; if (barrelAngles.x > idleBarrelAngle) { newAngle = Mathf.Max(barrelAngles.x - idleBarrelSpeed * Time.deltaTime, idleBarrelAngle); } else if (barrelAngles.x < idleBarrelAngle) { newAngle = Mathf.Min(barrelAngles.x + idleBarrelSpeed * Time.deltaTime, idleBarrelAngle); } barrelAngles.x = newAngle; barrel.transform.localEulerAngles = barrelAngles; if (!m_health.IsAlive()) { break; } float closestDist = Mathf.Infinity; GameObject closestEnemy = null; foreach (GameObject enemy in GameObject.FindGameObjectsWithTag("Enemy")) { float sqrDist1 = Vector3.ProjectOnPlane(enemy.transform.position - transform.position, Vector3.up).sqrMagnitude; if (sqrDist1 <= engageDist * engageDist) { if (sqrDist1 < closestDist) { closestDist = sqrDist1; closestEnemy = enemy; } } } if (closestEnemy != null) { m_target = closestEnemy; m_state = TurretState.ATTACKING; m_lastAttackTime = Time.time - Random.Range(attackCooldown * .4f, attackCooldown * 0.65f); } break; case TurretState.ATTACKING: bool needNewTarget = false; if (m_target == null) { needNewTarget = true; } else { float sqrDist = Vector3.ProjectOnPlane(m_target.transform.position - transform.position, Vector3.up).sqrMagnitude; if (sqrDist > (engageDist + 5) * (engageDist + 5)) { needNewTarget = true; } } if (needNewTarget) { float closestDist1 = Mathf.Infinity; GameObject closestEnemy1 = null; foreach (GameObject enemy in GameObject.FindGameObjectsWithTag("Enemy")) { if (!enemy.GetComponent <Health>().IsAlive()) { continue; } float sqrDist2 = Vector3.ProjectOnPlane(enemy.transform.position - transform.position, Vector3.up).sqrMagnitude; if (sqrDist2 <= engageDist * engageDist) { if (sqrDist2 < closestDist1) { closestDist = sqrDist2; closestEnemy = enemy; } } } if (closestEnemy1 != null) { m_target = closestEnemy1; } else { m_target = null; m_state = TurretState.IDLE; } } if (m_target == null) { break; } // Vector3 targetDir = m_target.transform.position - top.transform.position; Vector3 targetDirHoriz = targetDir; targetDirHoriz.y = 0f; Vector3 newTopDir = Vector3.Slerp(top.transform.forward, targetDirHoriz, 6f * Time.deltaTime); top.transform.rotation = Quaternion.LookRotation(newTopDir, Vector3.up); float targetAngle = Mathf.Asin(targetDir.y / targetDir.magnitude) * Mathf.Rad2Deg; targetAngle = 90f - targetAngle; barrel.transform.localEulerAngles = new Vector3(Mathf.Lerp(barrel.transform.localEulerAngles.x, targetAngle, 4f * Time.deltaTime), 0f, 0f); // if (Time.time > m_lastAttackTime + attackCooldown) { Timing.RunCoroutineSingleton(_AttackTarget(m_target), gameObject, "_AttackTarget", SingletonBehavior.Overwrite); } break; default: break; } }
public void TakeDamage(float amount) { Debug.Log("MinigunController:TakeDamage() - amount = " + amount); health -= amount; health = Mathf.Clamp(health, 0.0f, maxHealth); state = TurretStateManager.GetState(health); if (objSprite == null) return; UpdateSprite(); }