Exemplo n.º 1
0
    private void Update()
    {
        range = Vector3.Distance(playerPosition.position, transform.position);
        ApproachDestination();

        switch (m_pathStatus)
        {
        case PathBehavior.idle: destination = initialPosVec; break;

        case PathBehavior.followPath: aipbScript.PatrolBehavior(); break;

        case PathBehavior.followPlayer: destination = playerPosition.position; break;

        case PathBehavior.returnToPath: destination = initialPosVec; break;
        }

        switch (m_aggroStatus)
        {
        case Interaction.aggressive: break;

        case Interaction.interact: break;

        case Interaction.timid: transform.rotation = Quaternion.Euler(initialOrientation); break;

        case Interaction.unware: break;
        }

        if (Vector3.Distance(playerPosition.position, transform.position) < rangeOuterLimit)
        {
            isWithinRange = true;
//            Debug.Log("Player is within range of AI");
        }
        else
        {
            isWithinRange = false;
        }

        if (isWithinRange == true)
        {
            m_pathStatus = PathBehavior.followPlayer;
            DetectPlayer();
        }
        else
        {
            m_pathStatus = PathBehavior.followPath;
            if (Vector3.Distance(initialPosVec, transform.position) < rangeInnerLimit)
            {
                m_pathStatus = PathBehavior.followPath;
            }
        }


        if (m_aggroStatus == Interaction.unware &&
            (m_pathStatus == PathBehavior.idle) &&
            Vector3.Distance(initialPosVec, transform.position) < rangeInnerLimit)
        {
            transform.rotation = Quaternion.Euler(initialOrientation);
        }
    }
 public void ReadBase(ref BinaryReader br)
 {
     pathVersion  = br.ReadUInt32();
     pathName     = StringUtils.ReadWString(ref br);
     pathType     = (PathType)br.ReadUInt32();
     unknown1     = br.ReadUInt32();
     pathBehavior = (PathBehavior)br.ReadUInt32();
 }
Exemplo n.º 3
0
 private void Start()
 {
     m_aggroStatus       = Interaction.unware;
     m_pathStatus        = PathBehavior.followPath;
     m_baseRigidBody     = GetComponent <Rigidbody>();
     initialPosTransform = GetComponent <Transform>();
     initialPosVec       = initialPosTransform.position;
     initialOrientation  = initialPosTransform.rotation.eulerAngles;
     aipbScript          = GetComponent <AIPatrollingBehavior>();
 }
Exemplo n.º 4
0
    // Run once at the start of the game
    private void Start()
    {
        halfSize = GetComponent <SpriteRenderer>().bounds.size.x / 2;

        wrld = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, 0.0f, 0.0f));


        // Makes quite a few extras to account for higher speeds
        for (float y = 4; y < 16; y += .025f)
        {
            PathBehavior.CreateInitialObjects(y - 10);
        }
    }
Exemplo n.º 5
0
        /// <summary>
        ///  This creates the navigation path
        /// </summary>
        /// <param name="character"></param>
        private void BuildCharacterPath(Queue <Vec2> path, PathBehavior pathBehavior, int playerIndex, bool spawnLower, ref int targetFood)
        {
            Vec2 source = GetRandomBoundaryPoint(playerIndex, spawnLower).TransformToWorldSpace(mBoardController.Size);
            Vec2 target = new Vec2();

            switch (pathBehavior)
            {
            case PathBehavior.NoConnections:
            {
                Debug.WriteLine("NoConnections");
                // random target on same side
                while (true)
                {
                    target = GetRandomBoundaryPoint(playerIndex, spawnLower).TransformToWorldSpace(mBoardController.Size);
                    if (target != source)
                    {
                        break;
                    }
                }
                Queue <Vec2> subPath = new Queue <Vec2>();
                IAIManager.Instance.GetPath(source, target, subPath);

                // append sub path to path
                while (subPath.Count > 0)
                {
                    Vec2 wayPoint = subPath.Dequeue();
                    path.Enqueue(wayPoint);
                }

                break;
            }

            case PathBehavior.HasSingleConnections:
            {
                Debug.WriteLine("Single Connections");
                while (true)
                {
                    target = GetRandomBoundaryPoint(playerIndex, spawnLower).TransformToWorldSpace(mBoardController.Size);
                    if (target != source)
                    {
                        break;
                    }
                }

                Queue <Vec2> subPath = new Queue <Vec2>();
                IAIManager.Instance.GetPathWithInsideViaPoint(source, target, subPath, playerIndex, spawnLower);
                // append sub path to path
                while (subPath.Count > 0)
                {
                    Vec2 wayPoint = subPath.Dequeue();
                    path.Enqueue(wayPoint);
                }

                break;
            }

            case PathBehavior.HasFullConnections:
            {
                Debug.WriteLine("Full Connections");
                // get a target on the other side
                BoardController.GridPoint g = GetRandomBoundaryPoint(playerIndex, !spawnLower);
                if (playerIndex == 0)
                {
                    targetFood = g.mColumn;
                }
                else
                {
                    targetFood = g.mRow;
                }
                target = g.TransformToWorldSpace(mBoardController.Size);

                Queue <Vec2> subPath = new Queue <Vec2>();
                IAIManager.Instance.GetPath(source, target, subPath);

                // append sub path to path
                while (subPath.Count > 0)
                {
                    Vec2 wayPoint = subPath.Dequeue();
                    path.Enqueue(wayPoint);
                }
                break;
            }
            }
        }