コード例 #1
0
        public void Init()
        {
            anim                    = GetComponentInChildren <Animator>();
            audioSource             = this.gameObject.AddComponent <AudioSource>();
            audioSource.maxDistance = 3.5f;
            enTarget                = GetComponent <EnemyTarget>();
            enTarget.Init(this);

            rigid             = GetComponent <Rigidbody>();
            agent             = GetComponent <NavMeshAgent>();
            rigid.isKinematic = true;

            a_hook = anim.GetComponent <AnimatorHook>();
            if (a_hook == null)
            {
                // add AnimatorHook component to the active model.
                a_hook = anim.gameObject.AddComponent <AnimatorHook>();
            }

            enemyCanvas = GetComponentInChildren <Canvas>();

            a_hook.Init(null, this);
            InitRagDoll();
            parryIsOn = false;

            gameObject.layer = 8;
            ignoreLayers     = ~(1 << 9);

            lockOnGameObject.SetActive(false);
            healthBar = enemyCanvas.transform.Find("HealthBG").Find("Health").GetComponent <Image>();
            enemyCanvas.gameObject.SetActive(false);
            health = maxHealth;
        }
コード例 #2
0
ファイル: StateManager.cs プロジェクト: Dmacrush/Conqurer
        public bool CheckBossParry()
        {
            BossStates ParryTarget = null;


            Vector3 Orgin = transform.position;

            Orgin.y += 1;
            Vector3    RayDir = transform.forward;
            RaycastHit hit;

            if (Physics.Raycast(Orgin, RayDir, out hit, 3f, IgnoreLayers))
            {
                ParryTarget = hit.transform.GetComponentInParent <BossStates>();
            }

            if (ParryTarget == null)
            {
                return(false);
            }


            Vector3 dir = ParryTarget.transform.position - transform.position;

            dir.Normalize();
            dir.y = 0;
            float _angle = Vector3.Angle(transform.forward, dir);

            if (_angle < 60)
            {
                Vector3 targetPos = -dir * ParryOffset;
                targetPos         += ParryTarget.transform.position;
                transform.position = targetPos;


                if (dir == Vector3.zero)
                {
                    dir = -ParryTarget.transform.forward;
                }
                Quaternion ERotation = Quaternion.LookRotation(-dir);
                Quaternion ourRot    = Quaternion.LookRotation(dir);

                ParryTarget.transform.rotation = ERotation;
                transform.rotation             = ourRot;
                ParryTarget.IsGettingParried();


                CanMove     = false;
                InAction    = true;
                ParryIsOn   = false;
                EnemyTarget = null;


                return(true);
            }

            return(false);
        }
コード例 #3
0
        bool CheckForBackStab(Action slot)
        {
            if (slot.canBackStab == false)
            {
                return(false);
            }

            EnemyStates backstab = null;
            Vector3     origin   = transform.position;

            origin.y += 1;
            Vector3    rayDir = transform.forward;
            RaycastHit hit;

            if (Physics.Raycast(origin, rayDir, out hit, 1, ignoreLayers))
            {
                backstab = hit.transform.GetComponentInParent <EnemyStates>();
            }

            if (backstab == null)
            {
                return(false);
            }

            // direction calculated from the enemy to the player.
            Vector3 dir = transform.position - backstab.transform.position;

            dir.Normalize();
            dir.y = 0;
            float angle = Vector3.Angle(backstab.transform.forward, dir);

            if (angle > 150)
            {
                Vector3 targetPosition = dir * backstabOffset;
                targetPosition    += backstab.transform.position;
                transform.position = targetPosition;

                backstab.transform.rotation = transform.rotation;
                backstab.IsGettingBackStabbed(slot, inventoryManager.GetCurrentWeapon(slot.mirror));
                canAttack = false;
                onEmpty   = false;
                canMove   = false;
                inAction  = true;
                anim.SetBool("mirror", slot.mirror);
                anim.CrossFade("parry_attack", 0.2f);
                lockOnTarget = null;

                return(true);
            }

            return(false);
        }
コード例 #4
0
ファイル: StateManager.cs プロジェクト: Dmacrush/Conqurer
        public bool CheckForBackStab()
        {
            EnemyStates BackStab = null;

            Vector3 Orgin = transform.position;

            Orgin.y += 1;
            Vector3    RayDir = transform.forward;
            RaycastHit hit;

            if (Physics.Raycast(Orgin, RayDir, out hit, 1f, IgnoreLayers))
            {
                BackStab = hit.transform.GetComponentInParent <EnemyStates>();
            }

            if (BackStab == null)
            {
                return(false);
            }


            Vector3 dir = transform.position - BackStab.transform.position;

            dir.Normalize();

            dir.y = 0;
            float _angle = Vector3.Angle(BackStab.transform.forward, dir);

            if (_angle > 150)
            {
                Vector3 targetPos = dir * BackStabOffset;
                targetPos         += BackStab.transform.position;
                transform.position = targetPos;

                Anim.Play("Stab");
                BackStab.transform.rotation = transform.rotation;
                BackStab.IsGettingBackStab();

                CanMove  = false;
                InAction = true;

                // Need to change this shit..
                ParryIsOn = false;

                EnemyTarget = null;
                return(true);
            }

            return(false);
        }
コード例 #5
0
        bool CheckForBackstab(Action slot)
        {
            if (!slot.canBackstab)
            {
                return(false);
            }

            EnemyStates backstab = null;
            Vector3     origin   = transform.position;

            origin.y += 1f;
            Vector3 rayDir = transform.forward;

            RaycastHit hit;

            if (Physics.Raycast(origin, rayDir, out hit, 1f, ignoreLayers))
            {
                backstab = hit.transform.GetComponentInParent <EnemyStates> ();
            }

            if (backstab == null)
            {
                return(false);
            }

            Vector3 dir = transform.position - backstab.transform.position;

            dir.Normalize();
            dir.y = 0;
            float angle = Vector3.Angle(backstab.transform.forward, dir);

            if (angle > 150f)
            {
                Vector3 targetPosition = dir * backstabOffset;
                targetPosition    += backstab.transform.position;
                transform.position = targetPosition;

                backstab.transform.rotation = transform.rotation;
                backstab.IsGettingBackstabbed(slot);

                canMove  = false;
                inAction = true;
                anim.SetBool(StaticStrings.mirror, slot.mirror);
                anim.CrossFade(StaticStrings.parry_attack, .2f);
                lockOnTarget = null;
                return(true);
            }

            return(false);
        }
コード例 #6
0
        public EnemyTarget GetEnemy(Vector3 from)
        {
            EnemyTarget r       = null;
            float       minDist = float.MaxValue;

            for (int i = 0; i < enemyTargets.Count; i++)
            {
                float tDist = Vector3.Distance(from, enemyTargets [i].GetTarget().position);
                if (tDist < minDist)
                {
                    minDist = tDist;
                    r       = enemyTargets [i];
                }
            }

            return(r);
        }
コード例 #7
0
        private void Start()
        {
            health      = 100;
            anim        = GetComponentInChildren <Animator>();
            enemyTarget = GetComponent <EnemyTarget>();
            enemyTarget.Init(this);

            body = GetComponent <Rigidbody>();

            aHook = anim.GetComponent <AnimatorHook>();
            if (aHook == null)
            {
                aHook = anim.gameObject.AddComponent <AnimatorHook>();
            }
            aHook.Init(null, this);
            InitRagdoll();
        }
コード例 #8
0
        void Start()
        {
            health   = 1000;
            anim     = GetComponentInChildren <Animator> ();
            enTarget = GetComponent <EnemyTarget> ();
            enTarget.Init(this);

            rigid = GetComponent <Rigidbody> ();

            a_hook = anim.GetComponent <AnimatorHook> ();
            if (a_hook == null)
            {
                a_hook = anim.gameObject.AddComponent <AnimatorHook> ();
            }
            a_hook.Init(null, this);

            InitRagdoll();
            parryIsOn = false;
        }
コード例 #9
0
        bool CheckForParry(Action slot)
        {
            if (slot.canParry == false)
            {
                return(false);
            }


            EnemyStates parryTarget = null;
            Vector3     origin      = transform.position;

            origin.y += 1;
            Vector3    rayDir = transform.forward;
            RaycastHit hit;

            if (Physics.Raycast(origin, rayDir, out hit, 2, ignoreLayers))
            {
                parryTarget = hit.transform.GetComponentInParent <EnemyStates>();
            }

            if (parryTarget == null)
            {
                return(false);
            }

            if (parryTarget.parriedBy == null)
            {
                return(false);
            }

            //direction calculated from the player to the enemy.
            Vector3 dir = parryTarget.transform.position - transform.position;

            dir.Normalize();
            dir.y = 0;
            float angle = Vector3.Angle(transform.forward, dir);

            if (angle < 60)
            {
                Vector3 targetPosition = -dir * parryOffset;
                targetPosition    += parryTarget.transform.position;
                transform.position = targetPosition;

                if (dir == Vector3.zero)
                {
                    dir = -parryTarget.transform.forward;
                }

                Quaternion eRotation = Quaternion.LookRotation(-dir);
                Quaternion ourRot    = Quaternion.LookRotation(dir);

                parryTarget.transform.rotation = eRotation;
                transform.rotation             = ourRot;
                parryTarget.IsGettingParried(slot, inventoryManager.GetCurrentWeapon(slot.mirror));
                canAttack = false;
                onEmpty   = false;
                canMove   = false;
                inAction  = true;
                anim.SetBool("mirror", slot.mirror);
                anim.SetFloat("parrySpeed", 1);
                anim.CrossFade("parry_attack", 0.2f);
                lockOnTarget = null;


                return(true);
            }

            return(false);
        }
コード例 #10
0
        //--------------------runner------------------------
        public void FixedTick(float d)
        {
            delta              = d;
            isBlocking         = false;
            rigid.constraints &= ~RigidbodyConstraints.FreezePositionY;

            //-----------------Handle Actions and Interactions and States--------------------

            //_________Attack (inAction)_______
            if (onGround == true)
            {
                usingItem = anim.GetBool("interacting");
                anim.SetBool("spellcasting", isSpellCasting);
                if (inventoryManager.rightHandWeapon != null)
                {
                    inventoryManager.rightHandWeapon.weaponModel.SetActive(!usingItem);
                }
                if (inventoryManager.curConsumable != null)
                {
                    if (inventoryManager.curConsumable.itemModel != null)
                    {
                        inventoryManager.curConsumable.itemModel.SetActive(usingItem);
                    }
                }



                if (isBlocking == false && isSpellCasting == false)
                {
                    enableIK = false;
                }

                if (inAction)
                { //"inAction" evaluation.
                    anim.applyRootMotion = true;
                    _actionDelay        += delta;
                    if (_actionDelay > 0.3f)
                    { // Make Room: if the action is more than 0.3s, reset it again to make room for another action to take place.
                        inAction     = false;
                        _actionDelay = 0;
                    }
                    else
                    {
                        return;
                    }
                }
            }
            //_____Start of States______
            onEmpty = anim.GetBool("OnEmpty");
            //canMove = anim.GetBool("canMove");

            if (onEmpty)
            {
                canMove   = true;
                canAttack = true;
            }

            if (canRotate)
            {
                HandleRotation();
            }

            if (!onEmpty && !canMove && !canAttack) //Stop updating when all of the state managing variable is false (most likely the character is inAction)
            {
                return;
            }

            if (canMove && !onEmpty)
            {
                if (moveAmount > 0)
                {
                    anim.CrossFade("Empty Override", 0.1f);
                    onEmpty = true;
                }
            }

            if (canAttack)
            {
                DetectAction();
            }
            if (canMove)
            {
                DetectItemAction();
            }

            // turn off RootMotion after the animation is played.
            anim.applyRootMotion = false;

            if (inventoryManager.blockCollider.gameObject.activeSelf)
            {
                isInvincible = true;
            }

            //_____End of States_____

            // --------Handle movement and physics-------
            //physics
            if (moveAmount > 0 || !onGround)
            {
                rigid.drag = 0;
            }
            else
            {
                rigid.drag = 4;
            }

            //movement
            if (usingItem || isSpellCasting)
            {
                run        = false;
                moveAmount = Mathf.Clamp(moveAmount, 0, 0.5f);
            }

            if (onGround && canMove)
            {
                rigid.velocity = moveDir * (moveSpeed * moveAmount);
            }

            if (run)
            {
                moveSpeed = 5.5f;
                lockOn    = false;
            }
            else
            {
                moveSpeed = 3f;
            }

            HandleRotation();

            // ------Handle movement's animations------
            anim.SetBool("lockon", lockOn);
            if (lockOn == false)
            {
                HandleMovementAnimation();
            }
            else
            {
                HandleLockOnAnimations(moveDir);
            }

            //anim.SetBool("blocking", isBlocking);
            anim.SetBool("isLeft", isLeftHand);

            //________________________
            a_hook.useIK = enableIK;
            HandleBlocking();

            if (isSpellCasting)
            {
                HandleSpellCasting();
                return;
            }
            //_________________________

            //Rolls (inAction)
            a_hook.CloseRoll();
            if (onGround == true)
            {
                HandleRolls();
            }

            //_________________________
            if (lockOn == false)
            {
                lockOnTarget = null;
            }
            if (lockOnTarget != null)
            {
                lockOnTarget.isLockOn = true;
            }
        }
コード例 #11
0
ファイル: StateManager.cs プロジェクト: Dmacrush/Conqurer
        public bool CheckForParry()
        {
            EnemyStates ParryTarget = null;


            Vector3 Orgin = transform.position;

            Orgin.y += 1;
            Vector3    RayDir = transform.forward;
            RaycastHit hit;

            if (Physics.Raycast(Orgin, RayDir, out hit, 3f, IgnoreLayers))
            {
                ParryTarget = hit.transform.GetComponentInParent <EnemyStates>();
            }

            if (ParryTarget == null)
            {
                return(false);
            }

            /*  if(ParryTarget.ParriedBY == null)
             *    return false;*/


            /*    float distnace = Vector3.Distance(ParryTarget.transform.position,transform.position);
             *  if(distnace > 3f)
             *
             *      return false;*/

            Vector3 dir = ParryTarget.transform.position - transform.position;

            dir.Normalize();
            dir.y = 0;
            float _angle = Vector3.Angle(transform.forward, dir);

            if (_angle < 60)
            {
                Vector3 targetPos = -dir * ParryOffset;
                targetPos         += ParryTarget.transform.position;
                transform.position = targetPos;


                if (dir == Vector3.zero)
                {
                    dir = -ParryTarget.transform.forward;
                }
                Quaternion ERotation = Quaternion.LookRotation(-dir);
                Quaternion ourRot    = Quaternion.LookRotation(dir);

                ParryTarget.transform.rotation = ERotation;
                transform.rotation             = ourRot;
                ParryTarget.IsGettingParried();

                Anim.CrossFade("Parry", 0.01f);
                CanMove     = false;
                InAction    = true;
                ParryIsOn   = false;
                EnemyTarget = null;


                return(true);
            }

            return(false);
        }
コード例 #12
0
        bool CheckForParry(Action slot)
        {
            EnemyStates parryTarget = null;
            Vector3     origin      = transform.position;

            origin.y += 1;
            Vector3    rayDir = transform.forward;
            RaycastHit hit;

            if (Physics.Raycast(origin, rayDir, out hit, 3, ignoreLayers))
            {
                parryTarget = hit.transform.GetComponentInParent <EnemyStates>();
            }

            if (parryTarget == null)
            {
                return(false);
            }

            if (parryTarget.parriedBy == null)
            {
                return(false);
            }

            /*      float dis = Vector3.Distance(parryTarget.transform.position, transform.position);
             *
             *    if (dis > 3)
             *        return false;*/

            Vector3 dir = parryTarget.transform.position - transform.position;

            dir.Normalize();
            dir.y = 0;
            float angle = Vector3.Angle(transform.forward, dir);

            if (angle < 60)
            {
                Vector3 targetPosition = -dir * parryOffset;
                targetPosition    += parryTarget.transform.position;
                transform.position = targetPosition;

                if (dir == Vector3.zero)
                {
                    dir = -parryTarget.transform.forward;
                }

                Quaternion eRotation = Quaternion.LookRotation(-dir);
                Quaternion ourRot    = Quaternion.LookRotation(dir);

                parryTarget.transform.rotation = eRotation;
                transform.rotation             = ourRot;
                parryTarget.IsGettingParried();
                canMove  = false;
                inAction = true;
                anim.SetBool(StaticStrings.mirror, slot.mirror);
                anim.CrossFade(StaticStrings.parry_attack, 0.2f);
                lockOnTarget = null;
                return(true);
            }

            return(false);
        }