Exemple #1
0
    // Use this for initialization
    void Awake()
    {
        //Initialize state
        state = new AIState();
        state.MaxLinearAcceleration  = 5f;
        state.AngularVelocity        = 0f;
        state.MaxAngularAcceleration = 10f;
        state.MaxLinearVelocity      = new Vector3(5f, 0, 5f);
        state.MaxAngularVelocity     = 10f;
        state.LinearVelocity         = state.MaxLinearVelocity.magnitude * this.transform.forward;
        if (target != null)
        {
            Vector3 temp = target.position;
            temp.y       = 0;
            state.Target = temp;
        }
        else
        {
            state.Target = Vector3.zero;
        }

        //Reference animator
        animator = this.GetComponent <Animator>();
        //Mandatory Behaviours
        behaviours = new List <AIBehaviour>();

        AISeek seek = new AISeek(state, this.transform, 1f);

        behaviours.Add(seek);
        rayAvoid = new AIObjectAvoid(state, this.transform, 10f, seek);
        behaviours.Add(rayAvoid);
        behaviours.Add(new AIAlign(state, this.transform, 1f));
        separation = new AISeparate(state, this.transform, .3f);
        behaviours.Add(separation);
        avoid = new AICollisionAvoid(state, this.transform, 3f);
        behaviours.Add(avoid);

        if (BehaviourSetting == AIBehaviourType.ReachGoal)
        {
            behaviours.Add(new AIArrive(state, this.transform, .4f));
        }
        else if (BehaviourSetting == AIBehaviourType.Wander)
        {
            behaviours.Add(new AIWander(state, this.transform, .1f));
        }
    }
Exemple #2
0
	// Use this for initialization
	void Awake () {
		//Initialize state
		state = new AIState();
     	state.MaxLinearAcceleration = 5f;
		state.AngularVelocity = 0f;
		state.MaxAngularAcceleration = 10f;
		state.MaxLinearVelocity = new Vector3(5f, 0, 5f);
		state.MaxAngularVelocity = 10f;
		state.LinearVelocity = state.MaxLinearVelocity.magnitude * this.transform.forward;
		if(target != null){
		    Vector3 temp = target.position;
		    temp.y = 0;
		    state.Target = temp;
		}
		else
			state.Target = Vector3.zero;

		//Reference animator
		animator = this.GetComponent<Animator>();
		//Mandatory Behaviours
		behaviours = new List<AIBehaviour>();

		AISeek seek = new AISeek(state, this.transform, 1f);
		behaviours.Add (seek);
		rayAvoid = new AIObjectAvoid(state, this.transform, 10f, seek);
		behaviours.Add (rayAvoid);
		behaviours.Add (new AIAlign(state, this.transform, 1f));
		separation = new AISeparate(state, this.transform, .3f);
		behaviours.Add (separation);
		avoid = new AICollisionAvoid(state, this.transform, 3f);
		behaviours.Add (avoid);

        if(BehaviourSetting == AIBehaviourType.ReachGoal)
			behaviours.Add (new AIArrive(state, this.transform, .4f));
		else if(BehaviourSetting == AIBehaviourType.Wander)
			behaviours.Add (new AIWander(state, this.transform, .1f));
	}