// Use this for initialization
 void Start()
 {
     rb    = GetComponent <Rigidbody>();
     agent = GetComponent <NavMeshAgent>();
     seek  = GetComponent <SeekBehavior>();
     flee  = GetComponent <FleeBehavior>();
 }
Exemple #2
0
    public void Awake()
    {
        for (int i = 0; i < agentNumber; i++)
        {
            pos.x = Random.Range(-maxDistance, maxDistance);
            pos.y = Random.Range(-maxDistance, maxDistance);
            pos.z = Random.Range(-maxDistance, maxDistance);

            GameObject temp = Instantiate(prefab, pos, new Quaternion()) as GameObject;

            if (temp.GetComponent <SeekBehavior>() != null)
            {
                SeekBehavior sa = temp.GetComponent <SeekBehavior>();
                sa.target         = gameObject.transform;
                sa.steeringFactor = steeringBehavior;
            }
            if (temp.GetComponent <SeekArrive>() != null)
            {
                SeekArrive sa = temp.GetComponent <SeekArrive>();
                sa.target         = gameObject.transform;
                sa.steeringFactor = steeringBehavior;
                sa.radius         = radius;
            }

            MonoBoid mb = temp.GetComponent <MonoBoid>();
            mb.agent.position = pos;
            mb.mass           = Random.Range(minMass, maxMass);
            mb.agent.velocity = Vector3.up;
        }
    }
Exemple #3
0
 // Use this for initialization
 void Start()
 {
     startTimer = timer;
     wander     = GetComponent <WanderBehavior>();
     seek       = GetComponent <SeekBehavior>();
     arrive     = GetComponent <ArriveBehavior>();
 }
Exemple #4
0
 // Use this for initialization
 void Start()
 {
     distance = Vector3.Distance(target.transform.position, gameObject.transform.position);
     seek     = gameObject.GetComponent <SeekBehavior>();
     flee     = gameObject.GetComponent <FleeBehavior>();
     agent    = gameObject.GetComponent <NavMeshAgent>();
 }
Exemple #5
0
    public void FillInTheGrid()
    {
        Vector3 halfTheSize = new Vector3(m_Offset * (m_CollumsLegion * 0.5f), 0, m_Offset * (m_RowsLegion * 0.5f));
        Vector3 vec         = m_Hitpoint - halfTheSize;

        m_Agents.Sort(SortByDistance);

        for (int i = 0; i < m_AmountOfAgents; i++)
        {
            int   closestRow      = 0;
            int   closestCol      = 0;
            float closestDistance = float.MaxValue;

            if (m_Agents[i].GetCurrentRow() != -1 && m_Agents[i].GetCurrentCol() != -1)
            {
                if (m_LegionLayout[m_Agents[i].GetCurrentRow()][m_Agents[i].GetCurrentCol()] == false)
                {
                    closestRow      = m_Agents[i].GetCurrentRow();
                    closestCol      = m_Agents[i].GetCurrentCol();
                    closestDistance = Vector3.Distance(m_Agents[i].GetPosition(), new Vector3(vec.x + closestCol * m_Offset, vec.y, vec.z + closestRow * m_Offset));
                }
            }

            if (m_HasFormed == false)
            {
                for (int r = 0; r < m_RowsLegion; r++)
                {
                    for (int c = 0; c < m_CollumsLegion; c++)
                    {
                        if (m_LegionLayout[r][c] == false)
                        {
                            float distanceToGridPoint = Vector3.Distance(m_Agents[i].GetPosition(), new Vector3(vec.x + c * m_Offset, vec.y, vec.z + r * m_Offset));
                            if (closestDistance > distanceToGridPoint)
                            {
                                closestDistance = distanceToGridPoint;
                                closestCol      = c;
                                closestRow      = r;
                            }
                        }
                    }
                }
            }

            m_LegionLayout[closestRow][closestCol] = true;
            m_Agents[i].SetCurrentCol(closestCol);
            m_Agents[i].SetCurrentRow(closestRow);

            Vector3 target = vec + new Vector3(closestRow * m_Offset, 0, closestCol * m_Offset);

            SeekBehavior seek = new SeekBehavior();
            seek.SetTarget(target);
            m_Agents[i].SetSteeringBehavior(seek);
        }

        if (!m_HasFormed)
        {
            m_HasFormed = true;
        }
    }
 // Use this for initialization
 void Start()
 {
     timer  = transitionTime;
     agent  = GetComponent <NavMeshAgent>();
     wander = GetComponent <WanderBehavior>();
     seek   = GetComponent <SeekBehavior>();
     flee   = GetComponent <FleeBehavior>();
 }
Exemple #7
0
 // Use this for initialization
 void Start()
 {
     agent  = GetComponent <NavMeshAgent>();
     wander = GetComponent <WanderBehavior>();
     seek   = GetComponent <SeekBehavior>();
     flee   = GetComponent <FleeBehavior>();
     Energy = maxEnergy;
 }
Exemple #8
0
 // Use this for initialization
 void Start()
 {
     currentState = new Stack <IState>();
     wanderState  = GetComponent <WanderBehavior>();
     evadeState   = GetComponent <EvadeWander>();
     seekState    = GetComponent <SeekBehavior>();
     currentState.Push(seekState);
 }
Exemple #9
0
    // Constructor
    public WavePattern(Unit unit)
    {
        _unit = unit;

        seekBehavior    = new SeekBehavior(_unit);
        pursuitBehavior = new PursuitBehavior(_unit);

        reachTargetState  = new ReachTargetState(this, seekBehavior);
        attackTargetState = new AttackTargetState(this, seekBehavior);
        attackUnitState   = new AttackUnitState(this, pursuitBehavior);

        currentState = reachTargetState;
    }
Exemple #10
0
    // Constructor
    public RecruitmentPattern(Unit unit)
    {
        _unit = unit;

        waitBehavior    = new WaitBehavior(_unit);
        seekBehavior    = new SeekBehavior(_unit);
        pursuitBehavior = new PursuitBehavior(_unit);

        waitState           = new WaitState(this, waitBehavior);
        followLeaderState   = new FollowLeaderState(this, seekBehavior);
        holdPositionState   = new HoldPositionState(this, waitBehavior);
        defendPositionState = new DefendPositionState(this, pursuitBehavior);
        attackEnemyState    = new AttackEnemyState(this, pursuitBehavior);
        attackTargetState   = new AttackLeaderTargetState(this, seekBehavior);
        workState           = new WorkState(this, waitBehavior);

        currentState = waitState;
    }
Exemple #11
0
        protected override void OnInitialize()
        {
            MonsterBuilder builder = new BlobBuilder();

            builder.Build(Owner);

            Tree tree = CreateTree();

            tree.Initialize();

            Owner.AddComponent(tree);

            spriterComponent = new SpriterComponent <Texture2D>(Owner, @"Animations\Boss\Boss");
            spriterComponent.Initialize();
            spriterComponent.ChangeAnimation("Walk");
            spriterComponent.Scale = 0.75f;

            Owner.AddComponent(spriterComponent);

            steeringComponent = Owner.FirstComponentOfType <SteeringComponent>();

            SteeringBehavior seek = new SeekBehavior()
            {
                DesiredVelocity = new Vector2(1.25f),
                MaxSpeed        = 1.25f
            };

            steeringComponent.AddBehavior(seek);

            steeringComponent.ChangeActiveBehavior(typeof(SeekBehavior));

            rotation           = Owner.FirstComponentOfType <SkillRotation>();
            targetingComponent = Owner.FirstComponentOfType <TargetingComponent>();

            BossHealthComponent c = new BossHealthComponent(Owner);

            c.Initialize();
            Owner.AddComponent(c);

            rotation.Enable();
        }
Exemple #12
0
        // TODO: duplicated code. Crawlerilla melkein sama init logic.
        protected override void OnInitialize()
        {
            MonsterBuilder builder = new ZombieBuilder();

            builder.Build(Owner);

            Tree tree = CreateTree();

            tree.Initialize();

            Owner.AddComponent(tree);

            // Idle, Walk, Attack
            spriterComponent = new SpriterComponent <Texture2D>(Owner, @"Animations\GenericZombie\GenericZombie");
            spriterComponent.Initialize();
            spriterComponent.ChangeAnimation("Walk");
            spriterComponent.Scale = 0.5f;

            Owner.AddComponent(spriterComponent);

            steeringComponent = Owner.FirstComponentOfType <SteeringComponent>();

            SteeringBehavior flee = new FleeBehavior()
            {
                DesiredVelocity = new Vector2(4.25f),
                MaxSpeed        = 3.25f
            };

            SteeringBehavior seek = new SeekBehavior()
            {
                DesiredVelocity = new Vector2(4.25f),
                MaxSpeed        = 3.25f
            };

            steeringComponent.AddBehavior(flee);
            steeringComponent.AddBehavior(seek);

            steeringComponent.ChangeActiveBehavior(typeof(SeekBehavior));
        }
Exemple #13
0
        protected override void OnInitialize()
        {
            MonsterBuilder builder = new CrawlerBuilder();

            builder.Build(Owner);

            Tree tree = CreateTree();

            tree.Initialize();

            Owner.AddComponent(tree);

            spriterComponent = new SpriterComponent <Texture2D>(Owner, @"Animations\Crawler\crawler");
            spriterComponent.Initialize();
            spriterComponent.ChangeAnimation("NewAnimation");
            spriterComponent.Scale = 0.3f;

            Owner.AddComponent(spriterComponent);

            steeringComponent = Owner.FirstComponentOfType <SteeringComponent>();

            SteeringBehavior flee = new FleeBehavior()
            {
                DesiredVelocity = new Vector2(2.25f),
                MaxSpeed        = 1.25f
            };

            SteeringBehavior seek = new SeekBehavior()
            {
                DesiredVelocity = new Vector2(2.25f),
                MaxSpeed        = 1.25f
            };

            steeringComponent.AddBehavior(flee);
            steeringComponent.AddBehavior(seek);

            steeringComponent.ChangeActiveBehavior(typeof(SeekBehavior));
        }
 // Constructor
 public ReachTargetState(WavePattern statePatternEnemy, SeekBehavior seekBehavior)
 {
     state = statePatternEnemy;
     seek  = seekBehavior;
 }
 public AttackLeaderTargetState(RecruitmentPattern statePatternUnit, SeekBehavior seekBehavior)
 {
     state = statePatternUnit;
     seek  = seekBehavior;
 }
 // Constructor
 public FollowLeaderState(RecruitmentPattern statePatternUnit, SeekBehavior seekBehavior)
 {
     state = statePatternUnit;
     seek  = seekBehavior;
 }