// Our exit conditions are // a) we reach the player // b) we reach the players last known position and we can't find the player after x seconds (second half may be a new behavior) public override Status Update(ref Blackboard bb) { LOSInfo losResults = new LOSInfo(); if ((bb.LastKnownPlayerPosition - bb.Player.position).sqrMagnitude >= m_RefindPlayerDist) { losResults = CanSeePlayer(ref bb); if (losResults.CanSeePlayer) { bb.LastKnownPlayerPosition = bb.Player.position; bb.SetDestinationAndPath(bb.Player.position); } } else if (bb.ShowLOSCheck) { losResults = CanSeePlayer(ref bb); } bb.LOSCheck(losResults.CanSeePlayer, losResults.HitPoint); if (bb.LastKnownPlayerPosition == Vector3.zero) { // We don't have a destination, return failure //Debug.Log("ChasePlayer failed"); return Status.BH_FAILURE; } Vector3 toDestination = bb.Destination - bb.Trans.position; if (toDestination.sqrMagnitude <= m_DistanceThreshold * m_DistanceThreshold || bb.PathCurrentIdx >= bb.MovementPath.Length) { // If we've reached our destination, we're done Debug.Log ("ChasePlayer finish"); return Status.BH_SUCCESS; } // Move normally //Debug.DrawLine(bb.Trans.position, bb.MovementPath[bb.PathCurrentIdx], Color.green); Vector3 toNextPoint = bb.MovementPath[bb.PathCurrentIdx] - bb.Trans.position; toNextPoint.z = 0; if (toNextPoint.sqrMagnitude < 3) { ++bb.PathCurrentIdx; } toNextPoint.z = 0; toNextPoint.Normalize(); bb.Trans.Translate(toNextPoint * bb.MoveSpeed * Time.deltaTime); m_Status = Status.BH_RUNNING; return Status.BH_RUNNING; }