예제 #1
0
    public void newSeekForce(Transform waypoint, float weight = 1)
    {
        SeekForce temp = gameObject.AddComponent <SeekForce>();

        temp.waypoint = waypoint;
        temp.weight   = weight;
        temp.enabled  = true;
    }
 public void SetParameters(SeekForce seekForce, CastleScript castle)
 {
     foreach (Transform waypoint in castle.waypoints)
     {
         m_waypoints.Add(waypoint.position);
     }
     m_seekForce             = seekForce;
     m_currentWaypointNumber = 0;
     m_castle = castle;
 }
 public void SetParameters(BallScript ball, SeekForce seek, float timer, Vector3 middlePoint, float waypointDistance = 100f, float radius = 400f)
 {
     m_ball             = ball;
     m_timer            = timer;
     m_seekForce        = seek;
     m_middlePoint      = middlePoint;
     m_radius           = radius;
     m_waypointDistance = waypointDistance;
     m_time             = m_timer;
 }
    // Use for initialising the companion
    void Start()
    {
        // Turns off companion hack script, change the emission texture of the companion and make it moveable
        CompanionHackScript companionHack = gameObject.GetComponent <CompanionHackScript>();

        companionHack.enabled = false;
        GetComponent <Renderer>().material.SetTexture("_EmissionMap", companionTexture);
        GetComponent <Rigidbody>().isKinematic = false;


        // Initialise behaviour list
        m_behaviours = new List <IBehaviour>();

        // Find the player game object
        player       = FindObjectOfType <FPSController>().gameObject;
        playerScript = player.GetComponent <FPSController>();

        //-----------------------------------------------------------------
        // The Flee Sequence

        // Set up the flee force and flee force parameter
        m_fleeForce = new HorizontalFleeForce();
        m_fleeForce.SetTarget(player /*.transform.position + new Vector3 (2, 2, 2)*/);

        // Set up the flee behaviour
        fleeBehaviour = new SteeringBehaviour();
        fleeBehaviour.Constructor();
        fleeBehaviour.AddNewForce(m_fleeForce);

        // Set up condition for flee sequence
        WithinRange fleeCondition = new WithinRange();

        fleeCondition.SetParameters(player, 2.0f);

        // Set up flee sequence
        Sequence fleeSequence = new Sequence();

        fleeSequence.addBehaviour(fleeCondition);
        fleeSequence.addBehaviour(fleeBehaviour);



        //-----------------------------------------------------------------
        // The Chase Sequence

        // Set up the seek force and seek force parameter
        m_seekForce = new SeekForce();
        m_seekForce.SetTarget(player /*.transform.position + new Vector3 (2, 2, 2)*/);

        // Set up the seek behaviour
        seekBehaviour = new SteeringBehaviour();
        seekBehaviour.Constructor();
        seekBehaviour.AddNewForce(m_seekForce);

        // Set up condition for chase sequence
        WithinRange chaseCondition = new WithinRange();

        chaseCondition.SetParameters(player, 3.5f);

        // Set up the reverse condition
        NotCondition notChase = new NotCondition();

        notChase.SetCondition(chaseCondition);

        // Set up chase sequence
        Sequence chaseSequence = new Sequence();

        chaseSequence.addBehaviour(notChase);
        chaseSequence.addBehaviour(seekBehaviour);


        //-----------------------------------------------------------------
        // The In Range Sequence

        // Companion in range behaviour

        CompanionInRange inRangeBehaviour = new CompanionInRange();

        inRangeBehaviour.SetPlayer(player);


        //----------------------------------------------------------------
        // The Main Selector

        // Set up main selector
        Selector mainSelector = new Selector();

        mainSelector.addBehaviour(fleeSequence);
        mainSelector.addBehaviour(chaseSequence);
        mainSelector.addBehaviour(inRangeBehaviour);


        // Add all sequences to behaviour list
        m_behaviours.Add(mainSelector);

        // Setting the forward direction
        transform.forward = new Vector3(0, 0, 1);
    }
    // Use this for initialization
    void Start()
    {
        // Initialise behaviour list
        m_behaviours = new List <IBehaviour>();

        // Find the player game object
        player       = FindObjectOfType <FPSController>().gameObject;
        playerScript = player.GetComponent <FPSController>();

        currentHealth = maxHealth;

        //-----------------------------------------------------------------
        // The Flee Sequence

        // Set up the flee force and flee force parameter
        m_fleeForce = new HorizontalFleeForce();
        m_fleeForce.SetTarget(player /*.transform.position + new Vector3 (2, 2, 2)*/);

        // Set up the flee behaviour
        fleeBehaviour = new SteeringBehaviour();
        fleeBehaviour.Constructor();
        fleeBehaviour.AddNewForce(m_fleeForce);

        // Set up condition for flee sequence
        WithinRange fleeCondition = new WithinRange();

        fleeCondition.SetParameters(player, 1.5f);

        // Set up flee sequence
        Sequence fleeSequence = new Sequence();

        fleeSequence.addBehaviour(fleeCondition);
        fleeSequence.addBehaviour(fleeBehaviour);

        //-----------------------------------------------------------------
        // The Attack Sequence

        // Set up the attack behaviour
        ShootBehaviour attackBehaviour = new ShootBehaviour();

        attackBehaviour.SetTarget(player);
        attackBehaviour.SetWeaponType(ShootBehaviour.WeaponType.HitScanType);
        List <GameObject> guns = new List <GameObject>();

        // Give a list of bullet spawners to the shoot behaviour
        foreach (Transform child in transform)
        {
            GunParticleSystem gun;
            gun = child.gameObject.GetComponent <GunParticleSystem>();
            if (gun != null)
            {
                guns.Add(gun.gameObject);
            }
        }
        attackBehaviour.SetGuns(guns);

        // Set up condition for the attack sequence
        WithinRange attackCondition = new WithinRange();

        attackCondition.SetParameters(player, attackRange);

        // Set up play sound behaviour
        PlaySound playAttackSound = new PlaySound();

        if (stateAudioSource != null && attackStateClip != null)
        {
            playAttackSound.SetAudioSource(stateAudioSource);
            playAttackSound.SetAudioClip(attackStateClip);
            playAttackSound.SetTimer(15.0f);
        }

        // Set up attack sequence
        Sequence attackSequence = new Sequence();

        attackSequence.addBehaviour(attackCondition);
        if (stateAudioSource != null && attackStateClip != null)
        {
            attackSequence.addBehaviour(playAttackSound);
        }
        attackSequence.addBehaviour(attackBehaviour);



        //-----------------------------------------------------------------
        // The Chase Sequence

        // Set up the seek force and seek force parameter
        m_seekForce = new SeekForce();
        m_seekForce.SetTarget(player);

        // Set up the seek behaviour
        seekBehaviour = new SteeringBehaviour();
        seekBehaviour.Constructor();
        seekBehaviour.AddNewForce(m_seekForce);

        // Set up condition for chase sequence
        WithinRange chaseCondition = new WithinRange();

        chaseCondition.SetParameters(player, chaseRange);

        // Set up play sound behaviour
        PlaySound playChaseSound = new PlaySound();

        if (stateAudioSource != null && chaseStateClip != null)
        {
            playChaseSound.SetAudioSource(stateAudioSource);
            playChaseSound.SetAudioClip(chaseStateClip);
            playChaseSound.SetTimer(15.0f);
        }

        // Set up chase sequence
        Sequence chaseSequence = new Sequence();

        chaseSequence.addBehaviour(chaseCondition);
        if (stateAudioSource != null && chaseStateClip != null)
        {
            chaseSequence.addBehaviour(playChaseSound);
        }
        chaseSequence.addBehaviour(seekBehaviour);



        //----------------------------------------------------------------
        // The Patrol Sequence

        // Set up patrol behaviour
        PatrolBehaviour patrol = new PatrolBehaviour();

        patrol.SetPatrolPoints(m_patrolPointA, m_patrolPointB);
        patrol.StartUp();

        // Set up play sound behaviour
        PlaySound playPatrolSound = new PlaySound();

        if (stateAudioSource != null && chaseStateClip != null)
        {
            playPatrolSound.SetAudioSource(stateAudioSource);
            playPatrolSound.SetAudioClip(patrolStateClip);
            playPatrolSound.SetTimer(15.0f);
        }

        // Set up patrol sequence
        Sequence patrolSequence = new Sequence();

        if (stateAudioSource != null && chaseStateClip != null)
        {
            chaseSequence.addBehaviour(playPatrolSound);
        }
        patrolSequence.addBehaviour(patrol);

        //----------------------------------------------------------------
        // The Main Selector

        // Set up main selector
        Selector mainSelector = new Selector();

        mainSelector.addBehaviour(attackSequence);
        mainSelector.addBehaviour(chaseSequence);
        mainSelector.addBehaviour(patrolSequence);



        // Add all sequences to behaviour list
        m_behaviours.Add(mainSelector);

        // Setting the forward direction
        transform.forward = new Vector3(0, 0, 1);
    }
예제 #6
0
    // Use this for initialization
    void Start()
    {
        // Initialise behaviour list
        m_behaviours = new List <IBehaviour>();

        // Find the player game object
        player       = FindObjectOfType <FPSController>().gameObject;
        playerScript = player.GetComponent <FPSController>();


        //-----------------------------------------------------------------
        // The Collision Avoidance Sequence

        // Set up the collsion avoidance force



        ////-----------------------------------------------------------------
        //// The Attack Sequence

        //// Set up the attack behaviour
        //ShootBehaviour m_attackBehaviour = new ShootBehaviour();


        //// Set up condition for the attack sequence
        //WithinRange attackCondition = new WithinRange();
        //attackCondition.SetParameters(player, 5);

        //// Set up attack sequence
        //Sequence attackSequence = new Sequence();
        //attackSequence.addBehaviour(attackCondition);
        //attackSequence.addBehaviour(m_attackBehaviour);



//-----------------------------------------------------------------
// The Chase Sequence

        // Set up the seek force and seek force parameter
        m_seekForce = new SeekForce();
        m_seekForce.SetTarget(player);

        // Set up the seek behaviour
        seekBehaviour = new SteeringBehaviour();
        seekBehaviour.Constructor();
        seekBehaviour.AddNewForce(m_seekForce);

        // Set up condition for chase sequence
        WithinRange chaseCondition = new WithinRange();

        chaseCondition.SetParameters(player, 20);

        // Set up chase sequence
        Sequence chaseSequence = new Sequence();

        chaseSequence.addBehaviour(chaseCondition);
        chaseSequence.addBehaviour(seekBehaviour);



//----------------------------------------------------------------
// The Patrol Sequence

        // Set up patrol behaviour
        PatrolBehaviour patrol = new PatrolBehaviour();

        patrol.StartUp();
        patrol.SetPatrolPoints(new Vector3(20, 3, 12), new Vector3(-20, 3, 12));



//----------------------------------------------------------------
// The Main Selector

        // Set up main selector
        Selector mainSelector = new Selector();

        mainSelector.addBehaviour(chaseSequence);
        mainSelector.addBehaviour(patrol);



        // Add all sequences to behaviour list
        m_behaviours.Add(mainSelector);

        // Setting the forward direction
        transform.forward = new Vector3(0, 0, 1);
    }
    // Use this for initialization
    void Start()
    {
        // Initialise behaviour list
        m_castleScript = FindObjectOfType <CastleScript>();
        m_behaviours   = new List <IBehaviour>();

        m_body = GetComponent <Rigidbody>();
        if (!m_animator)
        {
            m_animator = GetComponentInChildren <Animator> ();
        }


        //-----------------------------------------------------------------
        // The Castle Interaction Sequence

        // Set up the seek force and seek force parameter
        SeekForce m_castleSeekForce = new SeekForce();

        m_castleSeekForce.m_rotationSpeed = turnSpeed;

        // Set waypoints
        foreach (Transform waypoint in waypoints)
        {
            waypointVectors.Add(waypoint.position);
        }

        // Set up the castle interaction behaviour
        CastleScript            castle         = FindObjectOfType <CastleScript>();
        CastleInteractBehaviour castleInteract = new CastleInteractBehaviour();

        castleInteract.SetParameters(m_castleSeekForce, castle);

        // Set up condition for castle interaction sequence
        CastleTouchedCondition castleCondition = new CastleTouchedCondition();

        castleCondition.castleScript = castle;

        //Set up chase sequence
        Sequence castleSequence = new Sequence();

        castleSequence.addBehaviour(castleCondition);
        castleSequence.addBehaviour(castleInteract);

        //-----------------------------------------------------------------
        // The Ball Interaction Sequence

        // Set up the seek force and seek force parameter
        SeekForce m_ballSeekForce = new SeekForce();

        m_ballSeekForce.m_rotationSpeed = turnSpeed;

        // Set up the ball interaction behaviour
        if (!ball)
        {
            ball = FindObjectOfType <BallScript> ();
        }
        BallInteractBehaviour ballInteract = new BallInteractBehaviour();

        ballInteract.SetParameters(ball, m_ballSeekForce, 10.0f, middleBallTarget);

        // Set up condition for ball interaction sequence
        BallTouchedCondition ballCondition = new BallTouchedCondition();

        ballCondition.m_ball        = ball;
        ballCondition.ballBehaviour = ballInteract;

        //Set up chase sequence
        Sequence ballSequence = new Sequence();

        ballSequence.addBehaviour(ballCondition);
        ballSequence.addBehaviour(ballInteract);



        //-----------------------------------------------------------------
        // The Chase Sequence

        // Set up the seek force and seek force parameter
        /*SeekForce seekChase*/ m_seekForce = new SeekForce();
        m_seekForce.SetTarget(player);

        // Set up the seek behaviour
        seekBehaviour = new SteeringBehaviour();
        seekBehaviour.Constructor();
        seekBehaviour.AddNewForce(m_seekForce);

        // Set up condition for chase sequence
        WaveCondition waveCondition = new WaveCondition();
        //waveCondition.m_target = player;

        // Set up chase sequence
        Sequence chaseSequence = new Sequence();

        chaseSequence.addBehaviour(waveCondition);
        chaseSequence.addBehaviour(seekBehaviour);


        //----------------------------------------------------------------
        // The Wander Sequence

        // Set up seek force and seek parameter
        SeekForce seekWander = new SeekForce();

        seekWander.m_rotationSpeed = turnSpeed;

        // Set up rotational force and arrival parameter
        RotationalForce rotationWander = new RotationalForce();

        // Set up arrival force and arrival parameter
        ArrivalForce arrivalWander = new ArrivalForce();

        arrivalWander.SetParameter();

        // Set up wander behaviour
        LimitedWanderBehaviour wanderBehaviour = new LimitedWanderBehaviour();

        wanderBehaviour.SetLimit(middlePoint, maxRadius, maxDepth);
        wanderBehaviour.SetForce(seekWander, rotationWander, arrivalWander);
        wanderBehaviour.nearEnough = m_waypointTolerance;

        //----------------------------------------------------------------
        // The Main Selector

        // Set up main selector
        Selector mainSelector = new Selector();

        mainSelector.addBehaviour(castleSequence);
        mainSelector.addBehaviour(ballSequence);
        mainSelector.addBehaviour(chaseSequence);
        mainSelector.addBehaviour(wanderBehaviour);

        // Add all sequences to behaviour list
        m_behaviours.Add(mainSelector);

        // Setting the forward direction
        transform.forward = new Vector3(0, 0, 1);
    }
예제 #8
0
 public void SetForce(SeekForce seekForce)
 {
     m_seekForce = seekForce;
 }
예제 #9
0
 // This is used to add new force for a specific behaviour
 public void SetForce(SeekForce seekForce, RotationalForce rotationalForce, ArrivalForce arrivalForce = null)
 {
     m_seekForce       = seekForce;
     m_arrivalForce    = arrivalForce;
     m_rotationalForce = rotationalForce;
 }