Example #1
0
    public bool Act(IContext context)
    {
        IWalker         walker          = (IWalker)context.GetVariable("IWalker");
        IFollower       follower        = (IFollower)context.GetVariable("IFollower");
        FacingDirection facingDirection = walker.GetFacingDirection();

        float maxWalkingSpeed = walker.GetWalkerSpeed();
        //= (float)context.GetVariable("maxWalkingSpeed");

        Vector2 myPosition = walker.GetWalkerTransform().position;
        Vector2 direction  = follower.GetCurrentWaypoint().GetWaypointPosition() - myPosition;

        direction.Normalize();

        if (direction.x > 0)
        {
            if (facingDirection == FacingDirection.LEFT)
            {
                walker.ChangeDirection(FacingDirection.RIGHT);
            }
            walker.MoveRight(maxWalkingSpeed);
        }
        else if (direction.x < 0)
        {
            if (facingDirection == FacingDirection.RIGHT)
            {
                walker.ChangeDirection(FacingDirection.LEFT);
            }
            walker.MoveLeft(maxWalkingSpeed);
        }
        return(true);
    }
    public bool ConditionPassed(IContext context)
    {
        IFollower follower = (IFollower)context.GetVariable("IFollower");

        return(follower.GetCurrentWaypoint().Reached((IWalker)follower));
    }