Example #1
0
    void Update()
    {
        //InfluenceMap.getInstance ().Show (0);
        if (!isStart)
        {
            return;
        }
        if (path.Count == 0 && Vector3.Distance(this.transform.position, target.transform.position) > 1.0f && tempTarget == Vector3.zero)
        {
            path = InfluenceMap.getInstance().AStarFindPath(this.gameObject.transform.position, target.transform.position, pAStarComputerformula);
            //Debug.Log (path.Count);
        }
        if (InfluenceMap.getInstance().isWall(InfluenceMap.getInstance().getTilefromPosition(new Vector2(tempTarget.x, tempTarget.z))))
        {
            path = InfluenceMap.getInstance().AStarFindPath(this.gameObject.transform.position, target.transform.position, pAStarComputerformula);
        }
        if (tempTarget == Vector3.zero && path != null)
        {
            if (path.Count != 0)
            {
                tempTarget = path.Pop();
            }
        }
        Vector3 v = new Vector3(tempTarget.x - this.transform.position.x, 0, tempTarget.z - this.transform.position.z);

        v.Normalize();
        if (Vector3.Distance(this.transform.position, tempTarget) > 1.0f)
        {
            this.transform.position += (v) * Time.deltaTime * Velocity;
        }
        else
        {
            tempTarget = Vector3.zero;
        }
    }
Example #2
0
    void Awake()
    {
        InfluenceMap.getInstance().center     = new Vector2(center.x, center.z);
        InfluenceMap.getInstance().DefaultY   = center.y;
        InfluenceMap.getInstance().height     = height;
        InfluenceMap.getInstance().width      = width;
        InfluenceMap.getInstance().htileCount = h_Tile;
        InfluenceMap.getInstance().wtileCount = w_Tile;
        InfluenceMap.getInstance().mPlane     = mPlane;
        InfluenceMap.getInstance().Init();
        GAPopulation.GlobalInit();
        GAPopulationManager.getInstance().Init();
        Type type = Type.GetType(DemoWorldName);

        aiWorld = (AIWorld)type.Assembly.CreateInstance(DemoWorldName);
        aiWorld.Init();
    }