// Use this for initialization
    void Start()
    {
        eventManager = FindObjectOfType <EventManager>();
        navAgent     = GetComponent <NavMeshAgent>();
        player       = FindObjectOfType <Player>();
        body         = GetComponent <Rigidbody>();
        triggerTag   = "Player";
        m_waypoints.TrimExcess();
        Debug.Log("Start target tag: " + triggerTag);

        animator = GetComponent <Animator>();

        // Detects if eye location is set
        if (!m_eyeLocation)
        {
            Debug.Log("Eye Location is not set");
        }

        // Detects if waypoints are set
        if (m_waypoints.Count < 1)
        {
            Debug.Log("Waypoints are not set");
        }

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

        // Set triggers to turn off
        List <string> offTriggers = new List <string>();

        offTriggers.Add("Search");
        offTriggers.Add("Chase");

        // Set up the attack behaviour
        PlayAnimation attackAnimation = new PlayAnimation();

        attackAnimation.SetParameters(animator, "DeathSequence", offTriggers);

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

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

        attackSequence.addBehaviour(attackCondition);
        attackSequence.addBehaviour(attackAnimation);

        // ---------------------------------------------------
        // The Drill Sequence

        // Set up the drill condition
        DrillBehaviour drillBehaviour = new DrillBehaviour();

        drillBehaviour.SetParameters(false);

        // Set up drill animation
        PlayAnimation drillAnimation = new PlayAnimation();

        drillAnimation.SetParameters(animator, "DrillSequence", null, onDoorDrilling);

        // Set up drill sequence
        Sequence drillSequence = new Sequence();

        drillSequence.addBehaviour(drillBehaviour);
        //drillSequence.addBehaviour(seekPanel);
        drillSequence.addBehaviour(drillAnimation);

        // ---------------------------------------------------
        // The Rage Sequence

        // Set up the rage condition
        DrillBehaviour rageBehaviour = new DrillBehaviour();

        rageBehaviour.SetParameters(true);

        // Set up rage animation
        PlayAnimation rageAnimation = new PlayAnimation();

        rageAnimation.SetParameters(animator, "RageSequence");

        // Set up rage sequence
        Sequence rageSequence = new Sequence();

        rageSequence.addBehaviour(rageBehaviour);
        rageSequence.addBehaviour(rageAnimation);

        //----------------------------------------------------
        // The Proximity Sequence

        // Set up within range condition for search sequence
        WithinRange withinSearch = new WithinRange();

        withinSearch.SetParameters(player.gameObject, m_searchRange);

        // Set up line of sight condition for search sequence
        LineOfSight inSight = new LineOfSight();

        inSight.SetParameters(player.gameObject, m_sightRange, m_eyeLocation);

        // Set up the close chase behaviour
        SetTargetBehaviour closeChase = new SetTargetBehaviour();

        closeChase.SetParameters(player.gameObject, m_searchSpeed, "CloseChase", onProximityDetection);

        // Set up arm extended animation
        PlayAnimation armExtended = new PlayAnimation();

        armExtended.SetParameters(animator, "ArmExtended");

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

        closeChaseSequence.addBehaviour(withinSearch);
        closeChaseSequence.addBehaviour(inSight);
        closeChaseSequence.addBehaviour(closeChase);
        closeChaseSequence.addBehaviour(armExtended);

        //----------------------------------------------------
        // The Search Sequence

        // Turn towards the player
        FaceTarget facePlayer = new FaceTarget();

        facePlayer.SetParameters(player.gameObject, m_rotationSpeed);

        // Set up arm extended animation
        PlayAnimation searchAnimation = new PlayAnimation();

        searchAnimation.SetParameters(animator, "Search", null, searching);

        // Set up search sequence
        Sequence searchSequence = new Sequence();

        searchSequence.addBehaviour(withinSearch);
        searchSequence.addBehaviour(facePlayer);
        searchSequence.addBehaviour(searchAnimation);

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

        // Set up the chase behaviour
        SetTargetBehaviour chasePlayer = new SetTargetBehaviour();

        chasePlayer.SetParameters(player.gameObject, m_chaseSpeed, "Chase", chasing);

        // Set up within range condition for chase sequence
        WithinRange withinChase = new WithinRange();

        withinChase.SetParameters(player.gameObject, m_sightRange);

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

        chaseSequence.addBehaviour(withinChase);
        chaseSequence.addBehaviour(inSight);
        chaseSequence.addBehaviour(chasePlayer);

        //----------------------------------------------------
        // The Investigate Sequence

        // Set up alert condition
        AlertCondition alertCondition = new AlertCondition();

        // Set up investigate sequence
        Sequence investigateSequence = new Sequence();

        investigateSequence.addBehaviour(alertCondition);
        investigateSequence.addBehaviour(m_investigateArea);


        //----------------------------------------------------
        // The Patrol Sequence
        // Set up the patrol targets
        Patrol patrolDestination = new Patrol();

        patrolDestination.SetParameters(m_waypoints);

        // Set up the patrol behaviour
        SetTargetBehaviour patrolBehaviour = new SetTargetBehaviour();

        patrolBehaviour.SetParameters(patrolDestination, m_patrolSpeed, "Patrol", patrolling);

        // Look for nearest waypoint then continue with the patrol from there

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

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

        mainSelector.addBehaviour(attackSequence);
        mainSelector.addBehaviour(drillSequence);
        mainSelector.addBehaviour(rageSequence);
        mainSelector.addBehaviour(closeChaseSequence);
        mainSelector.addBehaviour(searchSequence);
        mainSelector.addBehaviour(chaseSequence);
        mainSelector.addBehaviour(investigateSequence);
        mainSelector.addBehaviour(patrolBehaviour);

        // Add all sequences to the behaviour list
        m_behaviours.Add(mainSelector);
    }
    // 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);
    }
Exemplo n.º 3
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_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);
    }
Exemplo n.º 5
0
    // Use this for initialization
    void Start()
    {
        gameObject.tag = "Scarab";
        scarabAudio    = GetComponent <AudioSource> ();
        eventManager   = FindObjectOfType <EventManager>();
        navAgent       = GetComponent <NavMeshAgent>();
        player         = FindObjectOfType <Player>();
        body           = GetComponent <Rigidbody>();
        triggerTag     = "Player";

        m_sphereCollider = GetComponent <SphereCollider>();

        if (!animator)
        {
            animator = GetComponentInChildren <Animator>();
        }
        //m_animator = GetComponent<Animator>();

        //// Setting layers for Dr Leben's parts
        //foreach (Transform child in transform)
        //    child.gameObject.layer = gameObject.layer;

        // ---------------------------------------------------
        // The Death Sequence

        // Set up the
        IsScarabAttacked deathCheck = new IsScarabAttacked();

        Sequence deathSequence = new Sequence();

        deathSequence.addBehaviour(deathCheck);

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

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

        // Set up within range condition for chase sequence
        WithinRange withinAttack = new WithinRange();

        withinAttack.SetParameters(player.gameObject, m_attackRange);

        // Set Up Continue attack condition
        ContinueAttack continueAttackCondition = new ContinueAttack();

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

        attackBehaviour.SetParameters(player, m_damage, m_attackTimer, m_rotationSpeed, onAttack);

        // Set up line of sight condition for chase sequence
        LineOfSight inSight = new LineOfSight();

        inSight.SetParameters(player.gameObject, m_sightRange, m_eyeLocation);

        //// Set up component check enabled
        //ComponentEnabled navAgentCheck = new ComponentEnabled();
        //navAgentCheck.SetParameters(navMesh);

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

        attackSequence.addBehaviour(continueAttackCondition);
        //attackSequence.addBehaviour(navAgentCheck);
        //attackSequence.addBehaviour(attackCondition);
        attackSequence.addBehaviour(withinAttack);
        attackSequence.addBehaviour(inSight);
        //attackSequence.addBehaviour(facePlayer);
        attackSequence.addBehaviour(attackBehaviour);

        //----------------------------------------------------
        // The Face Target Sequence

        // Set up face target behaviour
        FaceTarget facePlayer = new FaceTarget();

        facePlayer.SetParameters(player.gameObject, m_rotationSpeed);

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

        faceTargetSequence.addBehaviour(continueAttackCondition);
        faceTargetSequence.addBehaviour(withinAttack);
        faceTargetSequence.addBehaviour(facePlayer);

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

        // Set up the chase behaviour
        SetTargetBehaviour chasePlayer = new SetTargetBehaviour();

        chasePlayer.SetParameters(player.gameObject, m_chaseSpeed, "", chasing);

        // Set up within range condition for chase sequence
        WithinRange withinChase = new WithinRange();

        withinChase.SetParameters(player.gameObject, m_chaseRange);

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

        chaseSequence.addBehaviour(continueAttackCondition);
        //chaseSequence.addBehaviour(navAgentCheck);
        chaseSequence.addBehaviour(withinChase);
        chaseSequence.addBehaviour(chasePlayer);

        //----------------------------------------------------
        // The Wander Sequence
        WanderTarget wanderSetter = new WanderTarget();

        SetTargetBehaviour wanderBehaviour = new SetTargetBehaviour();

        wanderBehaviour.SetParameters(wanderSetter, m_wanderSpeed, "", wandering);

        // Set up wander sequence
        Sequence wanderSequence = new Sequence();

        //wanderSequence.addBehaviour(navAgentCheck);
        wanderSequence.addBehaviour(wanderBehaviour);

        ////----------------------------------------------------
        //// The Attack Selector

        //// Set up main selector
        //Selector attackSelector = new Selector();
        //attackSelector.addBehaviour(attackSequence);
        //attackSelector.addBehaviour(chaseSequence);

        //----------------------------------------------------
        // The Sequence Selector


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

        mainSelector.addBehaviour(deathSequence);
        mainSelector.addBehaviour(attackSequence);
        mainSelector.addBehaviour(chaseSequence);
        mainSelector.addBehaviour(wanderSequence);

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

        // correct position so it always sits on navmesh
        NavMeshHit closestHit;

        if (NavMesh.SamplePosition(gameObject.transform.position, out closestHit, 500f, NavMesh.AllAreas))
        {
            gameObject.transform.position = closestHit.position;
        }
        else
        {
            Debug.LogError("Could not find position on NavMesh!");
        }
    }