예제 #1
0
 // Use this for initialization
 void Start()
 {
     playerCol    = GameObject.Find("RigidBodyFPSController").GetComponent <Collider>();
     AI_Behaviour = transform.root.GetComponent <AI_Behaviour>();
     camPlayer    = GameObject.Find("MainCamera").GetComponent <Transform>();
     power_Blink  = GameObject.Find("MainCamera").GetComponent <Power_Blink>();
 }
예제 #2
0
    public virtual void Init(Animator animator, AI_Brain brain, AI_Behaviour behaviour)
    {
        if (_initialized == false)
        {
            DisableState();
            _brain     = brain;
            _animator  = animator;
            _behaviour = behaviour;

            if (_behaviour != null)
            {
                m_fields = this.GetType()
                           .GetFields(BindingFlags.Instance | BindingFlags.Public)
                           .Where(field => field.GetCustomAttribute <AI_LinkData>() != null && field.FieldType.IsGenericType)
                           .ToArray();

                t_fields = _behaviour.GetType()
                           .GetFields(BindingFlags.Instance | BindingFlags.Public)
                           .Where(field => field.GetCustomAttribute <AI_LinkData>() != null && field.FieldType.IsGenericType)
                           .ToArray();

                m_eventMethods = this.GetType()
                                 .GetMethods(BindingFlags.Instance | BindingFlags.Public);

                LinkData();
                InitEvents();
            }

            _initialized = true;
        }
    }
예제 #3
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag == "Escapee")
     {
         AI_Behaviour ai = collision.GetComponent <AI_Behaviour>();
         ai.SetTurnDirection(dir);
     }
 }
예제 #4
0
    private void Awake()
    {
        playerScript = player.GetComponent <First_Person_Camera>();
        aiScript     = ai.GetComponent <AI_Behaviour>();

        player_win = 0;
        ai_win     = 0;
    }
예제 #5
0
 private bool IsLinked(AI_Behaviour behaviour, AI_State state)
 {
     if (behaviour.GetType().Name == state.GetType().Name.Substring(3) ||
         behaviour.LinkedStateName == state.GetType().Name)
     {
         return(true);
     }
     return(false);
 }
예제 #6
0
    public override void Start()
    {
        base.Start();
        NavAgent = GetComponent <NavMeshAgent>();

        // currentBehaviour = new Seek(this, behSettings);
        currentBehaviour = new GoTo(this, behSettings);
        currentBehaviour.OnStart();
    }
예제 #7
0
    void Start()
    {
        AI_behaviour = GetComponent <AI_Behaviour>();
        myAgent      = GetComponent <NavMeshAgent>();
        anim         = GetComponent <Animator>();

        if (startPatrol)
        {
            Invoke("StartPatrol", 0.5f);
        }
    }
예제 #8
0
 // Use this for initialization
 void Start()
 {
     AI_Behaviour = transform.root.gameObject.GetComponent <AI_Behaviour>();
     if (mainHealth)
     {
         SetKinematic(true, false);
     }
     hp            = maxHp;
     AI_HealthMain = transform.root.gameObject.GetComponent <AI_Health>();
     carryAndThrow = GameObject.Find("MainCamera").GetComponent <CarryAndThrow>();
     myBodyHips    = transform.root.Find("mixamorig:Hips").gameObject;
 }
    void Awake()
    {
        Player       = GetComponent <Component>();
        playerCam    = Player.GetComponent <Camera_Script>();
        player_state = playerCam.player_RPS_state;

        AI_Opponent = GetComponent <Component>();
        AI          = AI_Opponent.GetComponent <AI_Behaviour>();
        AI_signs    = AI.hand;

        rock_paper_scissor = true;
        directions_state   = false;
        reset();
    }
예제 #10
0
    public void FireHomingMissile()
    {
        Transform target = AI_Behaviour.GetClosestEnemy(transform.position);

        if (target == null)
        {
            return;
        }
        Vector3 startPosition       = new Vector3(transform.position.x, transform.position.y / 2f, transform.position.z - 2.5f);
        Bullet_HomingMissile bullet = GameObject.Instantiate(homingMissile.BulletData.BulletVisual, startPosition, transform.rotation).AddComponent <Bullet_HomingMissile>();
        BulletData           data   = GetHomingMissileData(homingMissile);

        bullet.SetBulletData(data);
        bullet.SetTarget(target);
    }
예제 #11
0
 protected override void Move(float deltaTime)
 {
     if (target != null)
     {
         Vector3 direction = target.position - transform.position;
         direction.Normalize();
         float rotateAmount = Vector3.Cross(direction, transform.forward).y *rotationSpeed;
         transform.Rotate(Vector3.up, -rotateAmount);
         speed = Mathf.MoveTowards(speed, targetSpeed, deltaTime * accelerationSpeed);
         transform.Translate(transform.forward * speed * deltaTime, Space.World);
     }
     else
     {
         target = AI_Behaviour.GetClosestEnemy(transform.position);
     }
 }
예제 #12
0
    // Use this for initialization
    void Start()
    {
        canvasGroup             = GetComponent <CanvasGroup>();
        canvasGroup.alpha       = 0;
        AI_Behaviour            = transform.root.GetComponent <AI_Behaviour>();
        UI_AwarenessMeter_White = transform.Find("UI_AwarenessMeter/UI_AwarenessMeter_White").GetComponent <Image>();
        UI_AwarenessMeter_Red   = transform.Find("UI_AwarenessMeter/UI_AwarenessMeter_Red").GetComponent <Image>();

        UI_AwarenessMeter_White.fillAmount = AI_Behaviour.awarenessMeter_White;
        UI_AwarenessMeter_Red.fillAmount   = AI_Behaviour.awarenessMeter_Red;

        camPlayer   = GameObject.Find("MainCamera").GetComponent <Transform>();
        AI_MainView = transform.root.Find("mixamorig:Hips/mixamorig:Spine/mixamorig:Spine1/mixamorig:Spine2/mixamorig:Neck/mixamorig:Head/MainView").GetComponent <AI_View>();

        duractionIAChasePlayer = AI_Behaviour.duractionIAChasePlayer;
    }
예제 #13
0
    private Transform[] CollectAllTransforms(AoEDamageEvent aoeEvent)
    {
        Transform[] aiTransforms     = AI_Behaviour.GetEnemiesWithinRadius(aoeEvent.SourcePosition, aoeEvent.Radius);
        Transform[] barrelTransforms = Barrel.GetBarrelsWithinRadius(aoeEvent.SourcePosition, aoeEvent.Radius);
        Transform[] all = new Transform[aiTransforms.Length + barrelTransforms.Length + 1];
        aiTransforms.CopyTo(all, 0);
        barrelTransforms.CopyTo(all, 0);

        if (Vector3.Distance(PlayerController.Position, aoeEvent.SourcePosition) < aoeEvent.Radius)
        {
            Transform playerTransform = PlayerController.GameObject.transform;
            all[all.Length - 1] = playerTransform;
        }

        return(all);
    }
예제 #14
0
    public void SwitchBehaviour(AI_Behaviour newBehaviour)
    {
        if (currentBehaviour == null)
        {
            currentBehaviour = newBehaviour;
            currentBehaviour.OnStart();
            previousBehaviour = currentBehaviour;
            return;
        }

        if (currentBehaviour != newBehaviour)
        {
            previousBehaviour = currentBehaviour;
            currentBehaviour.OnExit();
            currentBehaviour = newBehaviour;
            currentBehaviour.OnStart();
        }
    }
예제 #15
0
 private void OnStateChange(Animator animator, AI_Behaviour behaviour)
 {
     if (animator.gameObject != gameObject)
     {
         return;
     }
     foreach (AI_State ai in States)
     {
         if (IsLinked(behaviour, ai))
         {
             if (_activeState != null)
             {
                 _activeState.DisableState();
             }
             _activeState = ai;
             _activeState.EnableState();
             break;
         }
     }
 }
예제 #16
0
 private void LetAIFire(ref float timer, ref float fireRate, float min, float max, EnemyType type)
 {
     if (timer <= 0f)
     {
         if (enemyTypeBehaviour.ContainsKey(type) == true)
         {
             if (enemyTypeBehaviour[type].Count > 0)
             {
                 int          randomIndex = Random.Range(0, enemyTypeBehaviour[type].Count);
                 AI_Behaviour behaviour   = enemyTypeBehaviour[type][randomIndex];
                 if (behaviour.CanShoot == true)
                 {
                     behaviour.IsAllowedToShoot = true;
                     fireRate = Random.Range(min, max);
                     timer    = fireRate;
                 }
             }
         }
     }
 }
    // Update is called once per frame
    void Update()
    {
        RaycastHit hitInteract;

        if (globalState.playerKeyholePeek)
        {
            canInteract = false;
        }

        if (!air_Assassination.isAssassinating && canInteract && Physics.Raycast(transform.position, transform.forward, out hitInteract, 3))
        {
            if (hitInteract.transform.GetComponent <InteractableObject>() && hitInteract.transform.GetComponent <InteractableObject>().enabled)
            {
                RectTransform myRectTransform = cursor.rectTransform;
                myRectTransform.sizeDelta = new Vector2(16, 16);
                cursor.color  = Color.white;
                cursor.sprite = interact_Sprite;

                if (!carryAndThrow.isCarrying || (carryAndThrow.isCarrying && hitInteract.transform.tag != "Carryable"))
                {
                    isInteracted                    = true;
                    textCursor.text                 = hitInteract.transform.GetComponent <InteractableObject>().stringInteraction;
                    textDescription.text            = hitInteract.transform.GetComponent <InteractableObject>().stringDescription;
                    textCursorOption.text           = hitInteract.transform.GetComponent <InteractableObject>().stringInteractionOption;
                    barFeedback_Background.enabled  = (textCursorOption.text == "" ? false : true);
                    loadingBarFeedbackInput.enabled = (textCursorOption.text == "" ? false : true);

                    if (textCursorOption.text == "")
                    {
                        if (Input.GetButtonDown("Interaction"))
                        {
                            hitInteract.transform.GetComponent <InteractableObject>().PlayInteraction();
                        }
                    }

                    else

                    {
                        if (Input.GetButton("Interaction"))
                        {
                            timerLoadingInput += Time.deltaTime * 2;
                            loadingBarFeedbackInput.fillAmount = timerLoadingInput;

                            if (timerLoadingInput >= 1)
                            {
                                hitInteract.transform.GetComponent <InteractableObject>().PlayInteractionOption();
                                timerLoadingInput = 0;
                            }
                        }

                        else

                        {
                            timerLoadingInput = 0;
                            loadingBarFeedbackInput.fillAmount = 0.03f;
                        }

                        if (Input.GetButtonUp("Interaction") && timerLoadingInput < 1)
                        {
                            hitInteract.transform.GetComponent <InteractableObject>().PlayInteraction();
                        }
                    }
                }
            }

            else

            {
                RectTransform myRectTransform = cursor.rectTransform;
                myRectTransform.sizeDelta = new Vector2(2, 2);
                cursor.color                       = Color.white;
                cursor.sprite                      = basic_Sprite;
                textCursor.text                    = "";
                textDescription.text               = "";
                textCursorOption.text              = "";
                barFeedback_Background.enabled     = false;
                loadingBarFeedbackInput.enabled    = false;
                timerLoadingInput                  = 0;
                loadingBarFeedbackInput.fillAmount = 0.03f;
                isInteracted                       = false;
            }

            if (hitInteract.transform.gameObject.layer == 9 && hitInteract.distance < 2) //IA Enemy
            {
                cursor.color = Color.red;
                AI_Behaviour = hitInteract.transform.root.GetComponent <AI_Behaviour>();

                if (Vector3.Angle(transform.root.forward, hitInteract.transform.root.forward) < 60 && !AI_Behaviour.knockoutByChoke && AI_Behaviour.awarenessMeter_Red == 0 && !carryAndThrow.isCarrying && globalState.m_IsGrounded)
                {
                    UI_ChokeAndKill.SetActive(true);

                    if (Input.GetButtonDown("Choke"))
                    {
                        AI_Behaviour = hitInteract.transform.root.GetComponent <AI_Behaviour>();
                        AI_Behaviour.Choke(true);
                        previousCrouch = globalState.movementSettings.isCrouched;
                        globalState.movementSettings.isCrouched = false;
                        blade.SetActive(false);
                    }

                    if (Input.GetButtonDown("Attack") || Input.GetAxis("Attack") > 0.2f)
                    {
                        AI_Health    = hitInteract.transform.root.GetComponent <AI_Health>();
                        AI_Health.hp = 10;
                        AI_Behaviour = hitInteract.transform.root.GetComponent <AI_Behaviour>();
                        AI_Behaviour.Kill();
                    }
                }

                else

                if (!air_Assassination.canAssassinate && (!Input.GetButton("Choke") || (AI_Behaviour != null && (AI_Behaviour.isUnconscious || AI_Behaviour.knockoutByChoke))))
                {
                    UI_ChokeAndKill.SetActive(false);
                }
            }

            else

            {
                if (!air_Assassination.canAssassinate && (!Input.GetButton("Choke") || (AI_Behaviour != null && (AI_Behaviour.isUnconscious || AI_Behaviour.knockoutByChoke))))
                {
                    UI_ChokeAndKill.SetActive(false);
                }
            }
        }

        else

        {
            RectTransform myRectTransform = cursor.rectTransform;
            myRectTransform.sizeDelta = new Vector2(2, 2);
            cursor.color                       = Color.white;
            cursor.sprite                      = basic_Sprite;
            textCursor.text                    = "";
            textDescription.text               = "";
            textCursorOption.text              = "";
            barFeedback_Background.enabled     = false;
            loadingBarFeedbackInput.enabled    = false;
            timerLoadingInput                  = 0;
            loadingBarFeedbackInput.fillAmount = 0.03f;
            isInteracted                       = false;
            if (!air_Assassination.canAssassinate && (!Input.GetButton("Choke") || (AI_Behaviour != null && (AI_Behaviour.isUnconscious || AI_Behaviour.knockoutByChoke))))
            {
                UI_ChokeAndKill.SetActive(false);
            }
        }

        if (!globalState.playerKeyholePeek && Input.GetButtonUp("Interaction"))
        {
            canInteract = true;
        }

        if (Input.GetButtonUp("Choke"))
        {
            if (AI_Behaviour != null && !AI_Behaviour.knockoutByChoke)
            {
                AI_Behaviour.Choke(false);
                AI_Behaviour = null;
            }
            globalState.movementSettings.isCrouched = previousCrouch;
            previousCrouch = globalState.movementSettings.isCrouched;
            if (!carryAndThrow.isCarrying)
            {
                blade.SetActive(true);
            }
        }
    }
예제 #18
0
 private void Awake()
 {
     ai_choice = GetComponent <AI_Behaviour>();
     text.text = "A.I choose: " + ai_choice.ai_hands.ToString();
 }
예제 #19
0
    // Update is called once per frame
    void Update()
    {
        if (!controller.m_IsGrounded)
        {
            RaycastHit hitAssassination;

            if (!isAssassinating && !power_Blink.isBlinking && Physics.SphereCast(transform.position + Vector3.up * 0.5f, 1.2f, Vector3.down, out hitAssassination, 15, layerMaskAssassination))
            {
                if (hitAssassination.distance >= 2 && hitAssassination.transform.root.gameObject.layer == 9)   //Layer AI
                {
                    AI_Behaviour = hitAssassination.transform.root.gameObject.GetComponent <AI_Behaviour>();

                    if (!AI_Behaviour.isDead && !AI_Behaviour.isUnconscious)
                    {
                        UI_ChokeAndKill.SetActive(true);
                        canAssassinate = true;

                        if (Input.GetButtonDown("Attack") || Input.GetAxis("Attack") > 0.2f)
                        {
                            isAssassinating               = true;
                            targetAssassination           = hitAssassination.transform.root;
                            targetAssassination.position += Vector3.up * 0.1f;
                            AI_Behaviour = hitAssassination.transform.root.gameObject.GetComponent <AI_Behaviour>();
                            AI_Behaviour.AssassinationByKill();
                            blade.Attack();
                            speedMove = Vector3.Distance(transform.position, targetAssassination.position);
                        }

                        else

                        if (Input.GetButtonDown("Choke"))
                        {
                            isAssassinating               = true;
                            targetAssassination           = hitAssassination.transform.root;
                            targetAssassination.position += Vector3.up * 0.1f;
                            AI_Behaviour = hitAssassination.transform.root.gameObject.GetComponent <AI_Behaviour>();
                            AI_Behaviour.AssassinationByChoke();
                            speedMove = Vector3.Distance(transform.position, targetAssassination.position);
                        }
                    }
                }

                else

                {
                    UI_ChokeAndKill.SetActive(false);
                    canAssassinate = false;
                }
            }

            else

            {
                UI_ChokeAndKill.SetActive(false);
                canAssassinate = false;
            }
        }

        else

        {
            canAssassinate = false;
        }

        if (isAssassinating)
        {
            transform.position = Vector3.MoveTowards(transform.position, targetAssassination.position + Vector3.up * 0.8f - targetAssassination.forward * 0.2f, Time.deltaTime * speedMove * 1.5f);

            Quaternion orientation;
            orientation             = targetAssassination.rotation;
            orientation.eulerAngles = new Vector3(orientation.eulerAngles.x, orientation.eulerAngles.y + 180, orientation.eulerAngles.z);

            Quaternion orientationCam;
            orientationCam             = targetAssassination.rotation;
            orientationCam.eulerAngles = new Vector3(75, 0, 0);
            transform.rotation         = Quaternion.Slerp(transform.rotation, orientation, Time.deltaTime * 10);
            mainCamera.localRotation   = Quaternion.Slerp(mainCamera.localRotation, orientationCam, Time.deltaTime * 10);

            cam.fieldOfView = Mathf.MoveTowards(cam.fieldOfView, 35, Time.deltaTime * 30 * 2);

            timerAssassination += Time.deltaTime;
            mouseLook.canRotate = false;
            body.velocity       = new Vector3(0, body.velocity.y, 0);

            if (timerAssassination >= 1)
            {
                isAssassinating    = false;
                timerAssassination = 0;
                mouseLook.Init(transform, cam.transform);
                mouseLook.canRotate = true;
            }
        }
    }
예제 #20
0
 // Use this for initialization
 void Start()
 {
     AI_Behaviour = transform.root.gameObject.GetComponent <AI_Behaviour>();
     AI_Health    = transform.root.gameObject.GetComponent <AI_Health>();
 }