public override bool MoveAgent(GoapAction.WithContext nextAction) { // Move towards the NextAction's target. float step = moveSpeed * Time.deltaTime; var target = nextAction.target as Component; if (target == null || target.ToString() == "Null" || target.ToString() == "null") { return(false); } // NOTE: We must cast to Vector2, otherwise we'll compare the Z coordinate // which does not have to match! var position = (Vector2)target.transform.position; // TODO: Move by setting the velocity of a rigid body to allow collisions. transform.position = Vector2.MoveTowards(transform.position, position, step); if (position.Approximately(transform.position)) { // We are at the target location, we are done. nextAction.isInRange = true; return(true); } return(false); }
private bool Move3D(GoapAction.WithContext nextAction) { Component target = nextAction.target as Component; // Game object with name "NavTarget" marks where to navigate to Transform navTarget = target.transform.Find("NavTarget"); if (navTarget != null) { navAgent.SetDestination(navTarget.position); //navAgent.SetDestination(target.transform.position); } else { navAgent.SetDestination(target.transform.position); } if (!navAgent.pathPending) { if (navAgent.remainingDistance <= navAgent.stoppingDistance) { if (!navAgent.hasPath || navAgent.velocity.sqrMagnitude == 0f) { nextAction.isInRange = true; return(true); } } } return(false); }
public override void PlanAborted(GoapAction.WithContext aborter) { // An action bailed out of the plan. State has been reset to plan again. // Take note of what happened and make sure if you run the same goal again // that it can succeed. Debug.Log("<color=red>Plan Aborted</color> " + GoapAgent.PrettyPrint(aborter)); }
public override void PlanAborted(GoapAction.WithContext aborter) { // An action bailed out of the plan. State has been reset to plan again. // Take note of what happened and make sure if you run the same goal // again that it can succeed. Debug.Log("<color=red>Plan Aborted</color> " + aborter); textBubble.SetText("Hmp!"); }
public override bool MoveAgent(GoapAction.WithContext nextAction) { if (navAgent != null) { return(Move3D(nextAction)); } return(Move2D(nextAction)); }
public override void PlanAborted(GoapAction.WithContext aborter) { // An action bailed out of the plan. State has been reset to plan again. // Take note of what happened and make sure if you run the same goal // again that it can succeed. Debug.Log("<color=red>Plan Aborted</color> " + aborter); toughtBubble.SetActionText("Hmp!"); if (currentAction.successMsg != "") { toughtBubble.SetExtraText(currentAction.failMsg, false); } }
public override bool MoveAgent(GoapAction.WithContext nextAction) { // Move towards the NextAction's target. float step = moveSpeed * Time.deltaTime; var target = nextAction.target as Component; Vector2 position = target.transform.position; // TODO: Move by setting the velocity of a rigid body to allow collisions. gameObject.transform.position = Vector2.MoveTowards(gameObject.transform.position, position, step); if (position.Approximately((Vector2)gameObject.transform.position)) { // We are at the target location, we are done. nextAction.isInRange = true; return(true); } return(false); }
private bool Move2D(GoapAction.WithContext nextAction) { // Move towards the NextAction's target. float step = moveSpeed * Time.deltaTime; Component target = nextAction.target as Component; // NOTE: We must cast to Vector2, otherwise we'll compare the Z coordinate // which does not have to match! Vector2 position = (Vector2)target.transform.position; // TODO: Move by setting the velocity of a rigid body to allow collisions. transform.position = Vector2.MoveTowards(transform.position, position, step); if (position == (Vector2)transform.position) { // We are at the target location, we are done. nextAction.isInRange = true; return(true); } return(false); }
public override void AboutToDoAction(GoapAction.WithContext action) { textBubble.SetText(action.actionData.name); }
public override void AboutToDoAction(GoapAction.WithContext action) { toughtBubble.SetActionText(action.actionData.name); currentAction = action.actionData as ActionBase; }