Beispiel #1
0
        private void createMoveToState()
        {
            moveToState = (fsm, gameObj) =>
            {
                // move the game object

                GoapAction action = currentActions.Peek();
                if (action.requiresInRange() && action.target == null)
                {
                    Debug.Log(
                        "<color=red>Fatal error:</color> Action requires a target but has none. Planning failed." +
                        " You did not assign the target in your Action.checkProceduralPrecondition()");
                    fsm.popState();                     // move
                    fsm.popState();                     // perform
                    fsm.pushState(idleState);
                    return;
                }

                // get the agent to move itself
                if (dataProvider.moveAgent(action))
                {
                    fsm.popState();
                }
            };
        }
Beispiel #2
0
    private void createMoveToState()
    {
        moveToState = (fsm, gameObj) =>
        {
            Profiler.BeginSample("Move State Creation");
            // move the game object

            GoapAction action = currentActions.Peek();
            if (action.requiresInRange() && action.target == null)
            {
                //Debug.Log("<color=red>Fatal error:</color> Action " + action.ToString() +  " requires a target but has none. Planning failed. You did not assign the target in your Action.checkProceduralPrecondition()");
                fsm.popState(); // move
                fsm.popState(); // perform
                fsm.pushState(idleState);
                return;
            }
            if (action.interrupted)
            {
                //Debug.Log("<color=red>Fatal error:</color> Action " + action.ToString() +  " was interrupted by something ");
                fsm.popState();
                fsm.popState();
                fsm.pushState(idleState);
                return;
            }
            // get the agent to move itself
            if (dataProvider.moveAgent(action))
            {
                fsm.popState();
            }

            /*MovableComponent movable = (MovableComponent) gameObj.GetComponent(typeof(MovableComponent));
             *          if (movable == null) {
             *                  //Debug.Log("<color=red>Fatal error:</color> Trying to move an Agent that doesn't have a MovableComponent. Please give it one.");
             *                  fsm.popState(); // move
             *                  fsm.popState(); // perform
             *                  fsm.pushState(idleState);
             *                  return;
             *          }
             *          float step = movable.moveSpeed * Time.deltaTime;
             *          gameObj.transform.position = Vector3.MoveTowards(gameObj.transform.position, action.target.transform.position, step);
             *          if (gameObj.transform.position.Equals(action.target.transform.position) ) {
             *                  // we are at the target location, we are done
             *                  action.setInRange(true);
             *                  fsm.popState();
             *          }*/
            Profiler.EndSample();
        };
    }
Beispiel #3
0
    private void createMoveToState()
    {
        moveToState = (fsm, gameObject) => {
            AbstractGOAPAction action = currentActions.Peek();
            if (action.requiresInRange() && action.target == null)
            {
                fsm.popState();
                fsm.popState();
                fsm.pushState(idleState);
                return;
            }

            if (dataProvider.moveAgent(action))
            {
                fsm.popState();
            }
        };
    }
Beispiel #4
0
    private void createMoveToState()
    {
        moveToState = (fsm, gameObj) =>
        {
            // move the game object

            var action = currentActions.Peek();
//            if (action.requiresInRange() && action.target == null)
//            {
//                Debug.Log(
//                    "<color=red>Fatal error:</color> Action requires a target but has none. Planning failed. You did not assign the target in your Action.checkProceduralPrecondition()");
//                fsm.popState(); // move
//                fsm.popState(); // perform
//                fsm.pushState(idleState);
//                return;
//            }

            // get the agent to move itself
            if (dataProvider.moveAgent(action))
            {
                fsm.popState();
            }

            /*MovableComponent movable = (MovableComponent) gameObj.GetComponent(typeof(MovableComponent));
             *          if (movable == null) {
             *                  Debug.Log("<color=red>Fatal error:</color> Trying to move an Agent that doesn't have a MovableComponent. Please give it one.");
             *                  fsm.popState(); // move
             *                  fsm.popState(); // perform
             *                  fsm.pushState(idleState);
             *                  return;
             *          }
             *
             *          float step = movable.moveSpeed * Time.deltaTime;
             *          gameObj.transform.position = Vector3.MoveTowards(gameObj.transform.position, action.target.transform.position, step);
             *
             *          if (gameObj.transform.position.Equals(action.target.transform.position) ) {
             *                  // we are at the target location, we are done
             *                  action.setInRange(true);
             *                  fsm.popState();
             *          }*/
        };
    }
    private void createMoveToState()
    {
        moveToState = (fsm, gameObj) => {
            GoapAction action = currentActions.Peek();
            if (action.requiresInRange() && action.target == null && action.targetPosition.Equals(Vector3.zero))
            {
                // No target or target position
                Debug.Log("<color=red>Fatal error:</color> Action requires a target but has none. Planning failed. You did not assign the target in your Action.checkProceduralPrecondition()");
                fsm.popState(); // move
                fsm.popState(); // perform
                fsm.pushState(idleState);
                return;
            }

            // Call agent move funtion
            if (dataProvider.moveAgent(action))
            {
                fsm.popState();
            }
        };
    }
Beispiel #6
0
    private void createMoveToState()
    {
        moveToState = (fsm, gameObj) =>
        {
            GoapAction action = currentActions.Peek();
            if (action.requiresInRange() && action.target == null)
            {
                // Action needs agent to be in range but there is no target.
                Debug.Log("<color=red>Fatal error:</color> Action requires a target but has none.\n" +
                          "Planning failed. You did not assign the target in your Action.checkProceduralPrecondition()\n" +
                          "Action failed: " + prettyPrint(action));

                currentMoveToAttempts = 0;

                // Remove 'move' and 'perform' states from the FSM and go back to idle.
                fsm.popState();
                fsm.popState();
                fsm.pushState(idleState);
                return;
            }

            // If the agent moved and is now in range remove the 'move' state from the FSM.
            if (dataProvider.moveAgent(action))
            {
                currentMoveToAttempts = 0;
                fsm.popState();
            }

            if (++currentMoveToAttempts > maximumMoveToAttempts)
            {
                currentMoveToAttempts = 0;
                fsm.popState();
                fsm.popState();
                fsm.pushState(idleState);
                return;
            }
        };
    }