Example #1
0
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     if (guard == null)
     {
         guard = animator.gameObject.GetComponent <GuardAI>();
     }
     guard.Agent.SetDestination(guard.GuardStartPosition);
 }
Example #2
0
    void GuardAction(Collider guard)
    {
        NavMeshAgent nmAgent = guard.GetComponent <NavMeshAgent>();
        GuardAI      guardAI = guard.GetComponent <GuardAI>();

        nmAgent.SetDestination(transform.position + Random.insideUnitSphere * 4);
        guardAI.CoinDetected = true;
    }
 void Start()
 {
     wanderTarget       = Vector3.zero;
     otherAI            = gameObject.GetComponent <GuardAI> ();
     currentPatrolIndex = 0;
     currentPatrolPoint = patrolPoints[currentPatrolIndex];
     StartCoroutine(RotateObject(rotateGuardAngle, Vector3.forward, rotateGuardSpeed));
 }
Example #4
0
 public void OnExit(GuardAI ai)
 {
     if (ai.debugLogStates == true)
     {
         Debug.Log(name + ":OnExit");
     }
     _onExit(ai);
 }
Example #5
0
 protected override void _onUpdate(GuardAI ai)
 {
     ai.aiCharacterControl.SetTarget(ai.transform);
     if (Time.time >= exitStoppedStateTime)
     {
         _nextState = new FSMTransition(TransitionType.Reaction, ai.States[State.JogToLastPosition]);
     }
 }
Example #6
0
 public void OnUpdate(GuardAI ai)
 {
     if (ai.debugLogStates == true)
     {
         Debug.Log(name + ":OnUpdate");
     }
     _nextState = null;
     _onUpdate(ai);
 }
Example #7
0
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     if (guard == null)
     {
         guard = animator.gameObject.GetComponent <GuardAI>();
     }
     time        = Time.time;
     currentTime = guard.persistance / 5f;
     currentPos  = animator.gameObject.transform.position;
 }
Example #8
0
 protected override void _onUpdate(GuardAI ai)
 {
     if (ai.currentVisibleTarget != null)
     {
         _nextState = new FSMTransition(TransitionType.Reaction, ai.States[State.Chase]);
     }
     else if (ai.patrolPath.Count > 0)
     {
         _nextState = new FSMTransition(TransitionType.Planning, ai.States[State.Patrol]);
     }
 }
Example #9
0
    private void IncreaseDifficulty()
    {
        //Increase Difficulty
        difficulty++;
        difficultySpeed += difficultyAcceleration;
        difficultyTime  += (1f / difficultySpeed);

        //Spawn NPC
        Transform newSpawn = spawnPoints[Random.Range(0, spawnPoints.Length - 1)].transform;

        int ran = Random.Range(0, 4);

        if (ran == 0)
        {
            //Spawn Don with a 1 in 3 chance
            GameObject newNPC = (GameObject)Instantiate(donPrefab, newSpawn);
            newNPC.transform.parent = donParent;

            //Add to NPC List
            NPC._NPCs.Add(newNPC);

            GuardAI ai = newNPC.GetComponent <GuardAI> ();
            ai.maxSpeed      += 4f * ((float)difficulty / 30f);
            ai.sideStepSpeed += 1.5f * ((float)difficulty / 30f);
            ai.steeringSpd    = Mathf.Clamp01(ai.steeringSpd + (0.15f * ((float)difficulty / 30f)));
        }
        else
        {
            //Spawn Gaurd with a 2 in 3 chance
            GameObject newNPC = (GameObject)Instantiate(guardPrefab, newSpawn);
            newNPC.transform.parent = guardParent;

            //Add to NPC List
            NPC._NPCs.Add(newNPC);

            GuardAI ai = newNPC.GetComponent <GuardAI> ();
            ai.maxSpeed      += 3f * ((float)difficulty / 30f);
            ai.sideStepSpeed += 2.5f * ((float)difficulty / 30f);
            ai.steeringSpd    = Mathf.Clamp01(ai.steeringSpd + (0.2f * ((float)difficulty / 30f)));
        }

        //Spawn Ball
        int ranBall = Random.Range(0, 2);

        if (ranBall == 0)
        {
            GameObject newball = (GameObject)Instantiate(ballPrefab, newSpawn);
            newball.transform.parent = ballParent;
            newball.GetComponent <BallInit> ().Init(40f);
        }

        //Increases player speed
        playerCon.maxSpeed = 9f + (2.5f * ((float)difficulty / 30f));
    }
Example #10
0
    public void SetTransformOffsetForAnimation()
    {
        transform.GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Static;
        sneezingGuard    = transform.parent.gameObject;
        guard_ai         = sneezingGuard.GetComponent <GuardAI>();
        guard_ai.enabled = false;

        /// TODO: The rest of these

        transform.position += new Vector3(spriteRenderer.size.x * 3, 0);
    }
Example #11
0
    public static void PlayerCaught()
    {
        playerCaught = true;

        //Change AI target to the player's mech
        Transform newTarget = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerController>().ragdollBody;

        foreach (GameObject guard in _NPCs)
        {
            GuardAI ai = guard.GetComponent <GuardAI> ();
            ai.target = newTarget;
        }
    }
Example #12
0
    protected override void _onEnter(GuardAI ai)
    {
        exitConfusedStateTime = Time.time + UnityEngine.Random.Range(ai.confusionTimeMin, ai.confusionTimeMax);
        nextConfusedTurnTime  = Time.time + UnityEngine.Random.Range(0f, ai.reactionTimeMin);
        nextAngleY            = UnityEngine.Random.Range(-ai.maxConfusedTurnAngle, ai.maxConfusedTurnAngle);
        Vector3 eulerAngles = ai.transform.rotation.eulerAngles;

        nextAngle = Quaternion.Euler(
            eulerAngles.x,
            eulerAngles.y + nextAngleY,
            eulerAngles.z
            );
    }
Example #13
0
    void OnCollisionEnter(Collision col)
    {
        Vector3    pos = col.contacts [0].point;
        GameObject es  = (GameObject)GameObject.Instantiate(echoSphere, pos, Quaternion.identity);

        //float tauntRadius = tauntRadiusMul * Mathf.Abs (col.impulse.magnitude / rb.mass);
        //float tauntRadius = tauntRadiusMul * col.relativeVelocity.magnitude;

        float tauntRadius = tauntRadiusMul * Mathf.Max(Mathf.Abs(Vector3.Dot(col.contacts[0].normal, col.relativeVelocity)), Mathf.Abs(Vector3.Dot(col.impulse.normalized, col.relativeVelocity)));

        es.transform.localScale = Vector3.one * tauntRadius;
        EchoSphere es1 = es.GetComponent <EchoSphere> ();

        es1.SetMaxSize(tauntRadius);
        es1.Start();
        es1.ShowTap(pos, Color.red);
        Collider[] enemies = Physics.OverlapSphere(pos, tauntRadius, enemyMask, QueryTriggerInteraction.Ignore);

        foreach (Collider c in enemies)
        {
            GuardAI ai = FindAI(c);
            if (ai != null && ai.searching < 2)
            {
                ai.TauntPos(pos, true, 1);
            }
        }
        GuardAI ai2 = FindAI(col.collider);

        if (ai2 != null)
        {
            if (col.impulse.magnitude > 10 && pos.y - ai2.myTrans.position.y > 0.5f && Vector3.Distance(pos, ai2.myTrans.position + Vector3.up) <= 1.2f)
            {
                ai2.ctrl.AddBuff(BuffIndex.stun, 1);
            }
            else
            {
                ai2.TauntPos(pos, true, 3);
            }
        }
        if (Vector3.Distance(pos, nodes [nodes.Count - 1]) > 0.1f)
        {
            nodes.Add(pos);
            while (nodes.Count > 2)
            {
                nodes.RemoveAt(0);
            }
        }

        CurveCaster.singleton.StopAim(gameObject);
    }
Example #14
0
    GuardAI FindAI(Collider c)
    {
        GuardAI ai = c.GetComponent <GuardAI> ();

        if (ai == null)
        {
            ai = c.GetComponentInParent <GuardAI> ();
        }
        if (ai == null)
        {
            ai = c.GetComponentInChildren <GuardAI> ();
        }
        return(ai);
    }
Example #15
0
 protected override void _onUpdate(GuardAI ai)
 {
     if (Time.time >= attackEndTime)
     {
         if (GameController.Instance.playerKilled)//ai.currentVisibleTarget != null && Vector3.Distance(ai.transform.position, ai.currentVisibleTarget.transform.position) < 0.75f)
         {
             _nextState = new FSMTransition(TransitionType.Reaction, ai.States[State.KilledPlayer]);
         }
         else
         {
             _nextState = new FSMTransition(TransitionType.Reaction, ai.States[State.Chase]);
         }
     }
 }
    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.GetComponent <Collider2D>().CompareTag("Guard"))
        {
            Debug.Log("Collided");
            //GameObject.FindGameObjectWithTag("Guard").GetComponent<GuardAI>().enabled=false;

            guardHit         = col.GetComponent <GuardAI>();
            guardHit.enabled = false;

            player.GetComponent <Player> ().enabled = false;
            Debug.Log("Activated Fail Timer");
            GameObject.FindGameObjectWithTag("Guard").GetComponent <GuardFailTimer> ().FailTimerActivated(timetoresetLevel);
        }
    }
Example #17
0
    void SendAIToCoinSpot(Vector3 coinPosition)
    {
        GameObject[] guards = guards = GameObject.FindGameObjectsWithTag("Guard1");
        foreach (var guard in guards)
        {
            NavMeshAgent currentGuardAgent = guard.GetComponent <NavMeshAgent>();
            GuardAI      currentGuard      = guard.GetComponent <GuardAI>();
            Animator     currentGuardAnim  = guard.GetComponent <Animator>();

            currentGuard.coinPosition = coinPosition;
            currentGuard.coinTossed   = true;
            currentGuardAgent.SetDestination(coinPosition);
            currentGuardAnim.SetBool("Walk", true);
        }
    }
Example #18
0
    void SendAIToCoinSpot(Vector3 coinPos)
    {
        GameObject[] guards = GameObject.FindGameObjectsWithTag("Guard1");
        foreach (var guard in guards)
        {
            NavMeshAgent currentAgent = guard.GetComponent <NavMeshAgent>();
            GuardAI      currentGuard = guard.GetComponent <GuardAI>();
            Animator     currentAnim  = guard.GetComponent <Animator>();

            currentGuard.coinTossed = true;
            currentAgent.SetDestination(coinPos);
            currentAnim.SetBool("Walk", true);
            currentGuard.coinPos = coinPos;
        }
        //move guards to hitinfo point
        //navmeshagent.setdestination = coinPos
    }
Example #19
0
    private void SummonGuards(int _count)
    {
        for (int c = 0; c < _count; c++)
        {
            List <Vector2Int> _guardPatrolNode = new List <Vector2Int>();

            for (int i = 0; i < guardPatrolPathNodeCount; i++)
            {
                _guardPatrolNode.Add(GetRandomEmptyLocation());
            }
            _guardPatrolNode.Add(_guardPatrolNode[0]);

            List <Vector2Int>[] _guardPatrolPaths = new List <Vector2Int> [4];
            _guardPatrolPaths[0] = new List <Vector2Int>();
            for (int i = 0; i < _guardPatrolNode.Count - 1; i++)
            {
                List <Vector2Int> astar = AStarPathFromTo(_guardPatrolNode[i], _guardPatrolNode[i + 1]);

                for (int a = 0; a < astar.Count - 2;)
                {
                    if (HasDirectLineOFSight((Vector2)astar[a] * GameManager.roomGenerationFields.roomScale + (Vector2)this.transform.position, (Vector2)astar[a + 2] * GameManager.roomGenerationFields.roomScale + (Vector2)this.transform.position, 3.5f))
                    {
                        astar.RemoveAt(a + 1);
                    }
                    else
                    {
                        a++;
                    }
                }
                _guardPatrolPaths[0].AddRange(astar);
            }

            _guardPatrolPaths = GetReflectedPaths(_guardPatrolPaths[0]);

            for (int i = 0; i < 4; i++)
            {
                GuardAI _guard = Instantiate(GameManager.roomGenerationFields.guardGO, (Vector2)_guardPatrolPaths[i][0] * GameManager.roomGenerationFields.roomScale + (Vector2)this.transform.position, Quaternion.identity, this.transform).transform.GetComponent <GuardAI>();
                ////_guard.patrolIndex = _guardPatrolPaths[i].Count * i / 4;
                _guard.transform.position = (Vector2)_guardPatrolPaths[i][_guard.patrolIndex] * GameManager.roomGenerationFields.roomScale + (Vector2)this.transform.position;
                _guard.patrolPath         = _guardPatrolPaths[i];
                _guard.room = this;
                enemyTransforms.Add(_guard.transform);
            }
        }
    }
Example #20
0
 protected override void _onUpdate(GuardAI ai)
 {
     if (ai.currentVisibleTarget != null)
     {
         _nextState = new FSMTransition(TransitionType.Reaction, ai.States[State.Chase]);
     }
     else
     {
         if (Vector3.Distance(ai.transform.position, ai.nextPatrolTarget.transform.position) < 0.75f)
         {
             ai.nextPatrolTarget = ai.patrolPath[0];
             ai.patrolPath.Add(ai.patrolPath[0]);
             ai.patrolPath.RemoveAt(0);
             _nextState = new FSMTransition(TransitionType.Planning, ai.States[State.Patrol]);
         }
         ai.aiCharacterControl.SetTarget(ai.nextPatrolTarget.transform);
     }
 }
Example #21
0
    private void OnSceneGUI()
    {
        GuardAI fow = (GuardAI)target;

        Handles.color = Color.white;
        Handles.DrawWireArc(fow.transform.position, Vector3.forward, Vector3.right, 360, fow.viewRadius);
        Vector3 viewAngleA = fow.DirFromAngle(-fow.viewAngle / 2, false);
        Vector3 viewAngleB = fow.DirFromAngle(fow.viewAngle / 2, false);

        Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleA * fow.viewRadius);
        Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleB * fow.viewRadius);

        Handles.color = Color.red;
        foreach (Transform visibleTarget in fow.visiblePlayer)
        {
            Handles.DrawLine(fow.transform.position, visibleTarget.position);
        }
    }
Example #22
0
    protected override void _onUpdate(GuardAI ai)
    {
        if (ai.currentVisibleTarget != null)
        {
            _nextState = new FSMTransition(TransitionType.Reaction, ai.States[State.Chase]);
        }
        else
        {
            if (Time.time >= exitConfusedStateTime)
            {
                _nextState = new FSMTransition(TransitionType.Planning, ai.States[State.JogToLastPosition]);
            }
            else
            {
                if (Time.time >= nextConfusedTurnTime)
                {
                    // Turn left and right
                    ai.aiCharacterControl.SetTarget(null);
                    ai.transform.rotation = Quaternion.Slerp(ai.transform.rotation, nextAngle, Time.deltaTime * 5f);

                    if (Quaternion.Angle(ai.transform.rotation, nextAngle) < 0.1f)
                    {
                        float newAngle = UnityEngine.Random.Range(0f, ai.maxConfusedTurnAngle);
                        if (nextAngleY >= 0)
                        {
                            newAngle = -newAngle;
                        }
                        nextAngleY = newAngle;
                        Vector3 eulerAngles = ai.transform.rotation.eulerAngles;
                        nextAngle = Quaternion.Euler(
                            eulerAngles.x,
                            eulerAngles.y + nextAngleY,
                            eulerAngles.z
                            );

                        nextConfusedTurnTime = Time.time + UnityEngine.Random.Range(ai.planningTimeMin, ai.planningTimeMax);
                    }
                }
            }
        }
    }
 // Use this for initialization
 void Start()
 {
     guard      = GetComponent <GuardAI>();
     fov        = GetComponent <FieldOfView>();
     aiState    = AIState.Normal;
     alertSound = GetComponent <AudioSource>();
     Component[] meshes = GetComponentsInChildren <MeshRenderer>();
     foreach (MeshRenderer mesh in meshes)
     {
         if (mesh.name == "!")
         {
             exclamationPoint = mesh;
         }
         else if (mesh.name == "?")
         {
             questionMark = mesh;
         }
     }
     //exclamationPoint = GetComponentInChildren<MeshRenderer>();
     //questionMark = GetComponentInChildren<MeshRenderer>();
 }
Example #24
0
 protected override void _onUpdate(GuardAI ai)
 {
     if (ai.currentVisibleTarget != null)
     {
         ai.aiCharacterControl.SetTarget(ai.currentVisibleTarget);
         if (Vector3.Distance(ai.transform.position, ai.currentVisibleTarget.position) < 0.75f)
         {
             _nextState = new FSMTransition(TransitionType.Reaction, ai.States[State.Attacking]);
         }
     }
     else
     {
         ai.aiCharacterControl.SetTarget(ai.lastVisibleTarget);
         // Reached last visible target
         if (Vector3.Distance(ai.transform.position, ai.lastVisibleTarget.position) < 0.75f)
         {
             ai.lastVisibleTarget = null;
             _nextState           = new FSMTransition(TransitionType.Planning, ai.States[State.Confused]);
         }
     }
 }
Example #25
0
 protected override void _onUpdate(GuardAI ai)
 {
     if (ai.currentVisibleTarget != null)
     {
         _nextState = new FSMTransition(TransitionType.Reaction, ai.States[State.Chase]);
     }
     else
     {
         ai.aiCharacterControl.SetTarget(ai.nextPatrolTarget.transform);
         if (Vector3.Distance(ai.transform.position, ai.nextPatrolTarget.transform.position) < 0.75f)
         {
             if (Quaternion.Angle(ai.transform.rotation, ai.nextPatrolTarget.transform.rotation) > 0.1f)
             {
                 ai.transform.rotation = Quaternion.Slerp(ai.transform.rotation, ai.nextPatrolTarget.transform.rotation, Time.deltaTime * 5f);
             }
             else
             {
                 _nextState = new FSMTransition(TransitionType.Planning, ai.States[State.Idle]);
             }
         }
     }
 }
Example #26
0
    protected override void _onEnter(GuardAI ai)
    {
        transitionEndTime        = Time.time;
        nextTransitionActionTime = Time.time;

        initialRotation = ai.transform.rotation;
        ai.aiCharacterControl.SetTarget(ai.transform);

        switch (type)
        {
        case TransitionType.Reaction:
            transitionEndTime += UnityEngine.Random.Range(ai.reactionTimeMin, ai.reactionTimeMax);
            break;

        case TransitionType.Planning:
            transitionEndTime += UnityEngine.Random.Range(ai.planningTimeMin, ai.planningTimeMax);
            break;

        default:
            // no-op
            break;
        }
    }
    void spaceChange()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Debug.Log(currentGuardNum);
            currentGuardNum++;
            if (currentGuardNum == 5)
            {
                currentGuardNum = 0;
            }



            if (guardAIScript != null)
            {
                guardAIScript.playerControl = false;
                guardAIScript.changeColor(false);
            }
            currentGuard  = guards[currentGuardNum];
            guardAIScript = currentGuard.GetComponent <GuardAI>();
            guardAIScript.playerControl = true;
            guardAIScript.changeColor(true);
        }
    }
    void findClick()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, Mathf.Infinity))
            {
                Debug.Log(hit.transform.gameObject.name);

                if (hit.transform.gameObject.tag == "guard")
                {
                    if (guardAIScript != null)
                    {
                        guardAIScript.playerControl = false;
                        guardAIScript.changeColor(false);
                    }
                    currentGuard  = hit.transform.gameObject;
                    guardAIScript = currentGuard.GetComponent <GuardAI>();
                    guardAIScript.playerControl = true;
                    guardAIScript.changeColor(true);
                }
                else
                {
                    if (guardAIScript != null)
                    {
                        guardAIScript.playerControl = false;
                        guardAIScript.changeColor(false);
                    }
                    currentGuard  = null;
                    guardAIScript = null;
                }
            }
        }
    }
Example #29
0
 public bool IsAllowed(GuardAI flag)
 {
     return((m_Guard.GuardAI & flag) == flag);
 }
Example #30
0
    void Start()
    {
        player 			= 		GameObject.FindWithTag ("Player");
        navMeshAgent 	= 		GetComponent<NavMeshAgent> ();
        guardSensing 	= 		GetComponent<GuardSensing> ();
        guardAI 		= 		GetComponent<GuardAI> ();
        guardShooting 	= 		GetComponent<Shooting> ();
        anim 			= 		GetComponent<Animator> ();
        pHealth 		= 		GameObject.Find("Health Manager").GetComponent<HealthManager> ();
        guardBodyParts 	= 		GetComponent<GuardSelfDestruct> ();
        visionCone 		= 		transform.Find ("VisionCone").gameObject;

        // compile patrol and alert routes
        patrolRoute = new Vector3[4]
        {
            waypoint1.transform.position,
            waypoint2.transform.position,
            waypoint3.transform.position,
            waypoint2.transform.position
        };
        alertRoute = new Vector3[4]{
            alertWaypoint1.transform.position,
            alertWaypoint2.transform.position,
            alertWaypoint3.transform.position,
            alertWaypoint2.transform.position
        };
    }
Example #31
0
 public override void EnterState(GuardAI guard)
 {
     throw new System.NotImplementedException();
 }
Example #32
0
    void Start()
    {
        // Cache references to other scripts/components
        vision = gameObject.GetComponent<EnemySight> ();
        anim = GetComponent<Animator> ();
        alertAI = GetComponent<GuardAI> ();
        navMesh = gameObject.GetComponent<NavMeshAgent>();
        player = GameObject.FindWithTag ("Player");

        // initialise starting patrol points to 0 index
        nextIndex = 0;
        alertIndex = 0;

        // Compile array of waypoints for guard to patrol
        patrolRoute = new Vector3[4]
        {
            point1.transform.position,
            point2.transform.position,
            point3.transform.position,
            point2.transform.position
        };

        // Ditto, for the extra points to patrols when alerted
        alertRoute = new Vector3[4]{
            A_point1.transform.position,
            A_point2.transform.position,
            A_point3.transform.position,
            A_point2.transform.position,
            //point1.transform.position,
            //point2.transform.position,
            //point3.transform.position
        };

        // start patrolling at walking speed
        navMesh.SetDestination (patrolRoute[nextIndex]);
        anim.SetFloat ("Speed", 1.0f);
    }
Example #33
0
 void Start()
 {
     player = GameObject.FindWithTag ("Player");
     playerController = player.GetComponent<PlayerController>();
     guardAI = GetComponent<GuardAI> ();
     gBehaviour = GetComponent<GuardBehaviour> ();
     tScaler = GameObject.Find ("Time Manager").GetComponent<TimeScaler> ();
     if (tScaler.GetNoiseDampening ())
     {
         hearingRange = 2.5f;
     }
 }