//Animation state plays an animation such as shooting, swinging sword. The effect of the animation should be programmed outside of the GOAP system. //The GOAP system only plays animations and moves the agent void animateStateInit() { animateState = (fsm, gameObj) => { GOAPAction action = actionQueue.Peek(); if (action.isDone(this) && actionActivated) { // the action is done. Remove it so we can perform the next one actionActivated = false; actionQueue.Dequeue(); if (actionQueue.Count == 0) { fsm.popState(); fsm.pushState(idleState); } } else { if (action.requiresInRange) { //If an action requires to be in range of a type of object (set by the actions targetTag), we must find one and go to it before playing the animation target = FindClosestTarget(action.targetTag); if (target == null) { //No target. Action failed fsm.popState(); fsm.pushState(idleState); } else { //Only go to the target object if out of range if (Vector3.Distance(target.transform.position, this.transform.position) > action.range) { targetSet = false; fsm.pushState(goToState); } else if (action != currentAction) { //Otherwise activate the action currentAction = action; currentAction.activate(this); actionActivated = true; } } } else if (currentAction != action) { //Activate the current action currentAction = action; currentAction.activate(this); actionActivated = true; } } }; }