void moveTowardsPlayer() { if (Vector3.Distance(player.transform.position, transform.position) < attackRange) { enemyAction = attackPlayer; } float playerMoveSpeed = player.GetComponent <BoatController> ().getCurrentMoveSpeed(); // move towards some point in front of the player Vector3 targetPosition = player.transform.position + player.transform.forward * playerMoveSpeed; //Debug.Log (targetPosition); boat.steerToVector(targetPosition - transform.position); //transform.rotation = Quaternion.LookRotation(Vector3.RotateTowards (transform.forward, targetPosition, 5, 0)); // am I pointed towards that point? // forward is where the boat is facing // target - trans is the line from me to the target // these should be the same /* * float dot = Vector3.Angle ((targetPosition - transform.position).normalized, transform.forward); * Debug.Log ("Angle: " + dot + " forward: "+transform.forward + " line: "+ (targetPosition - transform.position).normalized); * boat.steer(dot / Mathf.Abs(dot)); * // Vector3.Distance(player.transform.position, transform.position) * * * Vector3 lineToPlayer = (player.transform.position - transform.position).normalized; * * boat.adjustThrottle (lineToPlayer.z); * boat.steer (lineToPlayer.x); */ }
void stopMoving() { // slow the boat down until it stops boat.adjustThrottle(-1.0f); if (boat.getCurrentMoveSpeed() < 0.1f) { enemyAction = sink; } }
void die() { // death // health component ran out of health so it called this enemyAction = stopMoving; if (Random.Range(0, 4) == 0) { dropCrew(); } }
void attackPlayer() { if (Vector3.Distance(player.transform.position, transform.position) > attackRange) { enemyAction = moveTowardsPlayer; } else if (boat.canShoot()) { boat.Shoot(calculateAimPosition()); } }
// Use this for initialization void Start() { if (player == null) { player = FindObjectOfType <CharacterController> ().gameObject; } boat = GetComponent <BoatController> (); enemyAction = attackPlayer; boat.adjustThrottle(1); GetComponent <Health> ().OnDeath += die; }
public Opponent(DecisionDelegate AI) { Engine.OpponentTurnStart += Engine_OpponentTurnStart; Engine.OpponentTurnEnd += Engine_OpponentTurnEnd; MakeDecision = AI; }
public void dieFromReset() { // called when the player dies enemyAction = stopMoving; }
public DecisionNode(DecisionDelegate decision, AI ai) { decisionDelegate = decision; aiAgent = ai; }