Exemplo n.º 1
0
    //sum up all the vectors from the individual steering forces
    //using that to guide our movement
    protected override void CalcSteeringForces()
    {
        //start with a zeroed-out vector
        Vector3 force = Vector3.zero;

        switch (leaderStates)
        {
            case LeaderStates.arriving:
                force += Arrival(wp[pointSeeking]);
                if (charController.velocity.magnitude < 0.3f)
                {
                    velocity *= 0.1f;
                    leaderStates = LeaderStates.stopping;
                }
                break;

            case LeaderStates.stopping:
                searchTime -= Time.deltaTime;
                if (searchTime <= 0)
                {
                    pointSeeking++;
                    if (pointSeeking >= wp.Count)
                    {
                        pointSeeking = 0;
                    }
                    leaderStates = LeaderStates.seeking;
                    searchTime = 2f;
                }
                break;

            case LeaderStates.seeking:
                force += Seek(wp[pointSeeking]) * seekWt;
                float inTheZone = 20f;
                if (Vector3.Distance(wp[pointSeeking], transform.position) < inTheZone)
                {
                    leaderStates = LeaderStates.arriving;
                }
                break;
            default:
                break;
        }

        //loop through all of the obstacles in the list
        foreach (GameObject o in obstacles)
        {
            force += AvoidObstacle(o, avoidDist) * avoidWt;
        }

        //limit the force by the max force float
        force = Vector3.ClampMagnitude(force, maxForce);

        //apply force
        ApplyForce(force);
    }
Exemplo n.º 2
0
    // Use this for initialization
    //Overridden from the base
    public override void Start()
    {
        base.Start();
        leaderStates = LeaderStates.seeking;
        obstacles = GameObject.FindGameObjectsWithTag("Tree");
        gm = GameObject.Find("MainGO").GetComponent<GameManager>();

        for (int i = 0; i < 6; i++)
        {
            wp.Add(GameObject.Find("Plant" + i).transform.position);
        }
    }
Exemplo n.º 3
0
 void Start()
 {
     // 设置ID
     SetID(++EntityManager.lastEntityID);
     //设置状态接口,并指向一个状态
     LeaderAC = this.gameObject.GetComponent <LocomotionLeader>();
     for (int i = 0; i < arraryOfVoices.Length; i++)
     {
         LeaderVoices.Add(arraryOfVoices[i].name, arraryOfVoices[i]);
     }
     voice = this.gameObject.GetComponent <AudioSource>();
     EntityManager.Instance().RegisterEntity(this);
     States          = this.gameObject.transform.FindChild("LeaderStates").GetComponent <LeaderStates>();
     m_pStateMachine = new StateMachine <Leader>(this);
     m_pStateMachine.SetCurrentState(States.IdleState);
 }