Пример #1
0
    public void CrearEstadoMoverse()
    {
        MoveState = (fsm, gameObj) => {
            GoapAction accion = AccionesActuales.Peek();
            // mover el agenbte hacia el objetivo de la accion si es que tiene
            if (accion.requiresInRange() && accion.Target == null)
            {
                Debug.Log("la accion drequere un targetm pero no tiene");
                fsm.popState(); // salri de actuar
                fsm.popState(); //salir de movers
                fsm.pushState(idleState);
                return;
            }

            //que se mueva
            if (goapData.MoveAgent(accion))
            {
                fsm.popState();
            }

            ////////////////////////////////////////////////////////////script de movimiento o de lo que quieras/////////////////////////////////////////
            gameObj.transform.position = Vector3.MoveTowards(
                gameObj.transform.position,
                accion.Target.transform.position,
                Time.deltaTime * 5
                );

            if (Vector3.Distance(gameObj.transform.position, accion.Target.transform.position) < 1f)
            {
                //llega al objetivo
                accion.SetInRange(true);
                fsm.popState();//salirde moverse
            }
        };
    }
Пример #2
0
        private void CreateMoveToState()
        {
            MoveToState = (fsm, agent) =>
            {
                GOAPAction Action = CurrentActions.Peek();
                if (Action.RequiresInRange() && Action.Target == null)
                {
                    fsm.PopState();
                    fsm.PopState();
                    fsm.PushState(IdleState);
                    return;
                }

                if (DataProvider.MoveAgent(Action))
                {
                    fsm.PopState();
                    AddThought("Performing action " + Action.ToString(), Color.Blue);
                }
            };
        }
Пример #3
0
        /// <summary>
        /// Starts acting on the plan by moving the agen
        /// </summary>
        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();
                }
            };
        }
Пример #4
0
    private void CrearEstadoMoverse()
    {
        MoveState = (fsm, gameObj) =>
        {
            GoapAction accion = AccionesActuales.Peek();
            // Mover al agente hacia el objetivo de la acción, si es que tiene
            if (accion.requiresInRange() && accion.Target == null)
            {
                Debug.Log("La acción requiere un target, pero no tiene");
                fsm.popState(); // salir de actuar
                fsm.popState(); // salir de moverse
                fsm.pushState(idleState);
                return;
            }

            // Que se mueva
            if (goapData.MoveAgent(accion))
            {
                // salir de idle o de actuar
                fsm.popState();
            }

            // código de movimiento
            gameObj.transform.position = Vector3.MoveTowards(
                gameObj.transform.position,
                accion.Target.transform.position,
                Time.deltaTime * 5f);

            if (Vector3.Distance(
                    gameObj.transform.position, accion.Target.transform.position) < 1f)
            {
                // llega al objetivo
                accion.SetInRange(true);
                fsm.popState(); //salir de moverse
            }
        };
    }