Exemplo n.º 1
0
        protected virtual void MoveTo(Vector3 position)
        {
            var delta    = position - transform.position;
            var movement = delta.normalized * GetSpeed();

            if (body != null)
            {
                if (UseRigidbodyVelocity)
                {
                    body.velocity = movement;
                }
                else
                {
                    body.MovePosition(transform.position + movement * Time.deltaTime);
                }
            }
            else
            {
                transform.position += movement * Time.deltaTime;
            }
            if (delta.magnitude <= MinDistanceToObjective)
            {
                currentState = GoToState.Success;
            }
            if (CheckForStuck && CheckIfStuck())
            {
                currentState = GoToState.Failure;
            }
        }
Exemplo n.º 2
0
    public void setParsingTable(Grammar extendedGrammar)
    {
        Dictionary <int, List <LR0Item> > canonicalCollection = this.items(extendedGrammar);

        foreach (var itemsList in canonicalCollection)
        {
            foreach (LR0Item item in itemsList.Value)
            {
                if (item.hasTerminalAfterPosition(this.grammar.terminals.ToArray()) && this.hasGoToState(itemsList.Value, item.getTerminalAfterPosition(this.grammar.terminals.ToArray())))
                {
                    Symbol    itemSymbol  = item.getTerminalAfterPosition(this.grammar.terminals.ToArray());
                    GoToState goToState   = this.getGoToState(item.uid);
                    int       goToStateId = this.getGoToStateId(goToState);
                    this.parseTable.parseActions.Add(new ActionInput(itemsList.Key, itemSymbol), new ActionResult(goToStateId, Action.Shift));
                }
                else if (item.hasHandle(this.grammar.nonTerminals.ToArray()))
                {
                    Symbol itemSymbol = item.getSymbolAfterPosition();
                    this.parseTable.parseActions.Add(new ActionInput(itemsList.Key, itemSymbol), new ActionResult(item.reduceProduction(this.states), Action.Reduce));
                }
                else if (item.isFirstItemInExtendedGrammar(this.grammar.nonTerminals.ToArray()))
                {
                    Symbol itemSymbol = Symbol.getEndMarker();
                    this.parseTable.parseActions.Add(new ActionInput(itemsList.Key, itemSymbol), new ActionResult(Action.Accept));
                }
            }
        }
    }
Exemplo n.º 3
0
        protected virtual void MoveTo(Vector3 position)
        {
            // Generate a path once.
            if (pathTarget == null || (position.x != pathTarget.x || position.y != pathTarget.y))
            {
                pathTarget = position;
                path       = GameManager.instance.pathfinder.GetPath(transform.position, position);
                if (path == null || path.Count <= 0)
                {
                    currentState = GoToState.Failure;
                    return;
                }

                Debug.Log("Regenerating path: " + path);
            }

            if (path.Count <= 0)
            {
                currentState = GoToState.Failure;
                return;
            }

            // Get the actual target from pathfinder.
            Vector3 actualtarget = path[0];

            if (transform.position == actualtarget)
            {
                path.Remove(actualtarget);
                return;
            }

            Vector3 delta    = (Vector3)actualtarget - transform.position;
            var     movement = delta.normalized * GetSpeed();

            if (UseRigidBody)
            {
                if (UseRigidbodyVelocity)
                {
                    body.velocity = movement;
                }
                else
                {
                    body.MovePosition(transform.position + movement * Time.deltaTime);
                }
            }
            else
            {
                transform.position += new Vector3(movement.x, movement.y, 0.0f) * Time.deltaTime;
            }
            if (delta.sqrMagnitude <= MinPowDistanceToObjective)
            {
                currentState = GoToState.Success;
            }
            if (CheckForStuck && CheckIfStuck())
            {
                currentState = GoToState.Failure;
            }
        }
Exemplo n.º 4
0
        // if you're using an animation just override this, call base function (base.Tick()) and then
        //  set the animator variables (if you want to use root motion then also override MoveTo)
        protected virtual void Tick()
        {
            var objectivePosition = objectiveTransform != null ? objectiveTransform.position : objective.GetValueOrDefault();

            if (nav.remainingDistance <= MinDistanceToObjective)
            {
                currentState = GoToState.Success;
            }
        }
Exemplo n.º 5
0
 //This method is used to return the id of a given GoToState
 public int getGoToStateId(GoToState goToState)
 {
     foreach (var state in this.goToStates)
     {
         if (state.Value == goToState)
         {
             return(state.Key);
         }
     }
     return(-1);
 }
Exemplo n.º 6
0
 public override void Enter()
 {
     base.Enter();
     if (nav.SetDestination(objective.Value))
     {
         nav.isStopped = false;
         currentState  = GoToState.Active;
     }
     else
     {
         nav.isStopped = true;
         currentState  = GoToState.Failure;
     }
 }
Exemplo n.º 7
0
        protected virtual void MoveTo(Vector3 position)
        {
            var delta    = position - transform.position;
            var movement = delta.normalized * GetSpeed();

            {
                transform.position += movement * Time.deltaTime;
            }
            if (delta.sqrMagnitude <= MinPowDistanceToObjective)
            {
                currentState = GoToState.Success;
            }
            if (CheckForStuck && CheckIfStuck())
            {
                currentState = GoToState.Failure;
            }
        }
Exemplo n.º 8
0
 public override void Enter()
 {
     base.Enter();
     currentState = GoToState.Active;
 }
Exemplo n.º 9
0
 void GoTo(Action onDoneMovement, Action onFailureMovement)
 {
     currentState              = GoToState.Pulsed;
     onDoneMovementCallback    = onDoneMovement;
     onFailureMovementCallback = onFailureMovement;
 }
Exemplo n.º 10
0
 private void CalcMovementPath()
 {
     speed = 5f;
     if (currentMovementState == null){
        		currentMovementState = GetGoToStateToPoint(currentGoal);
     }
     if (CalculatePath()){
         currentGoal = _pathFollowing.GetPoint();
     } else {
         if (character is NPC){ // the player should try to move near to the point instead of quiting
             OnNoPath();
         } else {
             GoToNearestNode();
         }
     }
 }