public override void Attack() { ShotCtrl.StartShotRoutine(); if (!isChanging && IdleDuration > 0) { isChanging = true; StartCoroutine(ChangeState(AIstates.Idle, AttackDuration)); } }
public override void Chase() { isReseting = true; // set to true, isReseting only affects turret after loosing target var pos = target.transform.position - transform.position; pos.y = 0; // zero out if you want to keep turret horizontal. var rot = Quaternion.LookRotation(pos); transform.rotation = Quaternion.Slerp(transform.rotation, rot, (Time.deltaTime * rotationSpeed) / rotationSpeedDamp); ShotCtrl.StartShotRoutine(); }
public override void Attack() { // rotate RotateToward(target.transform.position); ShotCtrl.StartShotRoutine(); var heading = target.transform.position - transform.position; if (heading.sqrMagnitude > ChaseRadius * ChaseRadius) // out of attack range { CurrentState = AIstates.Chase; } }
public override void Chase() { if (target == null) { isIdling = false; agent.speed = walkSpeed; agent.stoppingDistance = defaultStopDistance; ChangeState(AIstates.Idle); ShotCtrl.StopShotRoutineAndPlayingShot(); ChaseEvent.Invoke(false); } // TODO: Fix the repel //var enemyGO = GameObject.FindGameObjectsWithTag("Enemy"); //var repelForce = Vector3.zero; //foreach(GameObject enemy in enemyGO){ // if(enemy.transform == transform) continue; // if(Vector3.Distance(enemy.transform.position, transform.position) <= repelRange){ // repelForce += (transform.position - enemy.transform.position).normalized; // } //} if (target != null) { agent.speed = runSpeed; // var dir = (transform.position - target.transform.position).normalized; // Debug.Log("Dir: "+ dir); // Debug.Log("RepelForce: "+ repelForce); // TODO: we need to repel the enemies from one another so they don't stack on top of one another if ((transform.position - target.transform.position).sqrMagnitude > agent.stoppingDistance * agent.stoppingDistance) { agent.SetDestination(target.transform.position); } else // we are close enough to attack. Need to aim toward the player. { var pos = target.transform.position - transform.position; pos.y = 0; // zero out if you want to keep turret horizontal. var rot = Quaternion.LookRotation(pos); // Enemy Rotation transform.rotation = Quaternion.Slerp(transform.rotation, rot, (Time.deltaTime * rotationSpeed) / rotationSpeedDamp); var mountPos = target.transform.position - Mount.position; var mountRot = Quaternion.LookRotation(mountPos); // Mount Rotation Mount.rotation = Quaternion.Slerp(Mount.rotation, mountRot, (Time.deltaTime * rotationSpeed) / rotationSpeedDamp); ShotCtrl.StartShotRoutine(); } } }