void TrackClose() { if (obControl.player.isLight) { playerDirection = obControl.playerTarget.transform.position - transform.position; playerDistance = Vector3.Distance(obControl.playerTarget.transform.position, transform.position); playerAngle = Vector3.Angle(playerDirection, transform.forward); // Check if the gun still sees the player. If not, change to SCAN if (playerAngle > detectionAngle) { enemyState = EnemyState.SCAN; } // Check is player is still within close tracking distance. If not, change to TRACK_FAR if (playerDistance > closeTrackDistance) { enemyState = EnemyState.TRACK_FAR; } // Rotate gun to track player position steeringBasics.LookAtDirection(obControl.playerTarget.transform.position); CheckRotationBounds(); // Check if player location is in front of gun and shoot if (steeringBasics.IsInFront(obControl.playerTarget.transform.position)) { shootGun = true; } } else { enemyState = EnemyState.SCAN; } }
void StateResolution() { switch (enemyState) { case EnemyState.PATROL: //Debug.Log("State = Patrol"); patrol.PatrolMovement(); break; case EnemyState.PERSUE: //Debug.Log("State = Persue"); accel = pursue.getSteering(playerRB); steeringBasics.steer(accel); steeringBasics.LookAtDirection(); //pursue.getSteering(playerRB); CheckFire(player.transform.position); break; case EnemyState.EVADE: //Debug.Log("State = Evade"); evade.GetSteering(playerRB); CheckFire(player.transform.position); break; case EnemyState.CLOSE: evade.GetCloseSteering(playerRB); break; } }
public void GetSteering(Rigidbody target) { // Calculate the distance to the target Vector3 displacement = target.position - transform.position; float distance = displacement.magnitude; // Get the targets's speed float speed = target.velocity.magnitude; // Calculate the prediction time float prediction; if (speed <= distance / maxPrediction) { prediction = maxPrediction; } else { prediction = distance / speed; //Place the predicted position a little before the target reaches the character prediction *= 0.9f; } // Set where the AI thinks the target will be and look at it Vector3 explicitTarget = target.position + target.velocity * prediction; if (distance < closingDistance) { steeringBasics.LookAtDirection(target.position); } else { steeringBasics.LookAtDirection(explicitTarget); } // Enemy evasive maneuvers SetStrafeDirection(); Vector3 combinedMovement = back + (right * strafeDirection); transform.Translate(combinedMovement * maxAcceleration * Time.deltaTime); }
void TrackClose() { playerDirection = obControl.playerTarget.transform.position - transform.position; playerDistance = Vector3.Distance(obControl.playerTarget.transform.position, transform.position); playerAngle = Vector3.Angle(playerDirection, transform.forward); // Check is player is still within close tracking distance. If not, change to TRACK_FAR if (playerDistance > closeTrackDistance) { enemyState = EnemyState.TRACK_FAR; } // Rotate gun to track player position steeringBasics.LookAtDirection(obControl.playerTarget.transform.position); // Check if player location is in front of gun and shoot if (steeringBasics.IsInFront(obControl.playerTarget.transform.position)) { ShootGun(); } }