public override Status Update(ref Blackboard bb) { int xDist = Random.Range(-12, 12); int yDist = Random.Range(-12, 12); Vector3 newLocation = new Vector3(xDist + bb.StartPoint.x, yDist + bb.StartPoint.y, bb.Trans.position.z); if ((newLocation - bb.Trans.position).sqrMagnitude >= 5) { //Debug.Log("PickRandomPoint found new point"); bb.SetDestinationAndPath(newLocation); return Status.BH_SUCCESS; } //Debug.Log("PickRandomPoint failed to find point"); return Status.BH_RUNNING; }
public override Status Update(ref Blackboard bb) { RaycastHit2D hitInfo = Physics2D.Raycast(bb.Trans.position, bb.ToPlayer2D.normalized, 150); if (hitInfo && hitInfo.transform.tag == "Player") { Debug.Log("AI can see player"); bb.TimeSincePlayerLOS = 0.0f; bb.SetDestinationAndPath(bb.Player.position); return Status.BH_SUCCESS; // is returning Success here mean we're goin to OnIntialize next frame? } else if (bb.TimeSincePlayerLOS >= m_TimeBeforeBailingOut) { // We don't currently have sight of the player, and we don't have a history // of viewing the player, so we fail return Status.BH_FAILURE; } // We must have some history of viewing the player (aka TimeSincePlayerLOS < m_TimmeBeforeBailingOut) // so we'll increment the timer bb.TimeSincePlayerLOS += Time.deltaTime; return Status.BH_RUNNING; }
public override Status Update(ref Blackboard bb) { if (bb.Beacon == Vector3.zero) { // no beacon exists for us to travel to, return failure //Debug.Log("Failed to find beacon"); return Status.BH_FAILURE; } // else a beacon exists, we are attracted to beacons, let's go to it! if (bb.Beacon != bb.Destination) { bb.SetDestinationAndPath(bb.Beacon); } return Status.BH_SUCCESS; }
// 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; }