private void Update()
    {
        if (ai == null || ssw == null || ssl == null)
        {
            return;
        }

        GunAtt gunAtt = ai.GetCurrentWeaponScript();

        if (gunAtt)
        {
            if (Mathf.Abs(immutedTargetX - cImmuted.x) < eps)
            {
                immutedTargetX = (immutedSignX ? -1 : 1) * Random.Range(0, ssw.WHandIKProps.immutedWeaponSpreadAgentMultiplier.x * gunAtt.immutedSpreadMax.x);
                immutedSignX   = !immutedSignX;
            }
            if (Mathf.Abs(immutedTargetY - cImmuted.y) < eps)
            {
                immutedTargetY = (immutedSignY ? -1 : 1) * Random.Range(0, ssw.WHandIKProps.immutedWeaponSpreadAgentMultiplier.y * gunAtt.immutedSpreadMax.y);
                immutedSignY   = !immutedSignY;
            }
            Vector2 immutedTarget = new Vector2(immutedTargetX, immutedTargetY);
            cImmuted = Vector2.Lerp(cImmuted, immutedTarget, Time.deltaTime * ssw.WHandIKProps.immutedSpreadChangeSpeed);

            transform.localPosition = Vector3.Lerp(transform.localPosition, defLocalPos + new Vector3(cImmuted.x, cImmuted.y, 0), gunAtt.spreadRecoverSpeed * ssw.WHandIKProps.weaponSpreadRecoverAgentMultiplier);
            ssw.weaponBodyBob       = Mathf.Lerp(ssw.weaponBodyBob, 0, gunAtt.bodyRecoverSpeedInverse * ssl.LookIKProps.weaponBodyRecoverSpeedMultiplier * Time.deltaTime);
        }
    }
示例#2
0
        virtual public void OnNewClipInLeftHand(AIBrain ai)
        {
            GunAtt gunAtt = ai.GetCurrentWeaponScript();

            // instantiate new clip in left hand
            if (gunAtt && gunAtt.curClipObject && gunAtt.curClipPrefab)
            {
                // instantiate new clip
                tempNewClip = gunAtt.InstantiateReturn(gunAtt.curClipPrefab);
                tempNewClip.SetParent(LeftHandHold, true);

                tempNewClip.localPosition = Vector3.zero;
                tempNewClip.localRotation = Quaternion.identity;

                LeftHandHold.localPosition = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.LeftHandClip).localPosition;
                LeftHandHold.localRotation = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.LeftHandClip).localRotation;

                tempNewClip.GetComponent <Rigidbody>().isKinematic = true;
                tempNewClip.GetComponent <Collider>().enabled      = false;

                gunAtt.StartCoroutine(gunAtt.FixClipPosInLHand(tempNewClip));

                return;
            }
        }
示例#3
0
        public override void ReloadWeapon(AIBrain ai)
        {
            ai.stateSystemAnimator.AnimateTrigger(
                ai, "Reload",
                false, false, "", "LowIdle", 1);
            ReleaseLeftHandFromWeapon(ai);

            // Drop current clip object from weapon if there is
            GunAtt gunAtt = ai.GetCurrentWeaponScript();

            if (gunAtt != null && gunAtt.curClipObject && gunAtt.curClipPrefab)
            {
                gunAtt.curClipObject.SetParent(null);
                if (gunAtt.curClipObject.GetComponent <Rigidbody>())
                {
                    gunAtt.curClipObject.GetComponent <Rigidbody>().AddForce(ai.Transform.forward * 1f);
                    gunAtt.curClipObject.GetComponent <Rigidbody>().isKinematic = false;
                }
                if (gunAtt.curClipObject.GetComponent <Collider>())
                {
                    gunAtt.curClipObject.GetComponent <Collider>().enabled   = true;
                    gunAtt.curClipObject.GetComponent <Collider>().isTrigger = false;
                }
                if (gunAtt.curClipObject.GetComponent <Destroy>())
                {
                    gunAtt.curClipObject.GetComponent <Destroy>().destroyTime = 30f;
                }
            }
        }
示例#4
0
        public override bool IsWeaponArmingFinished(AIBrain ai)
        {
            if (ai.stateSystemAnimator.IsStartedAnimationFinished("", "LowIdle"))
            {
                // Just in case
                GunAtt gunAtt = ai.GetCurrentWeaponScript();
                if (RightHandHold && ai.HaveCurrentWeapon() && gunAtt &&
                    gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AnimRightHand))
                {
                    RightHandHold.localPosition = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AnimRightHand).localPosition;
                    RightHandHold.localRotation = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AnimRightHand).localRotation;

                    WeaponIK.localPosition = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AimHipFire).localPosition;
                    WeaponIK.localRotation = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AimHipFire).localRotation;
                }

                ai.CurrentWeapon.SetParent(RightHandHold, false);
                ai.CurrentWeapon.localPosition = Vector3.zero;
                ai.CurrentWeapon.localRotation = Quaternion.identity;

                return(true);
            }

            return(false);;
        }
示例#5
0
        private void HandleWeaponHandsOnAnimatorIK(AIBrain ai)
        {
            if (WeaponIK)
            {
                ai.Animator.SetIKPosition(AvatarIKGoal.RightHand, WeaponIK.position + WeaponIK.right * WHandIKProps.aimPositionFixer.x + WeaponIK.up * WHandIKProps.aimPositionFixer.y + WeaponIK.forward * WHandIKProps.aimPositionFixer.z);
                ai.Animator.SetIKRotation(AvatarIKGoal.RightHand, WeaponIK.rotation * Quaternion.Euler(WHandIKProps.aimRotationFixer) * WHandIKProps.weaponSpread);
                ai.Animator.SetIKPositionWeight(AvatarIKGoal.RightHand, WHandIKProps.rHandAim);
                ai.Animator.SetIKRotationWeight(AvatarIKGoal.RightHand, WHandIKProps.rHandAimRot);
            }

            Transform leftHandleOfGun = ai.GetCurrentWeaponScript() && ai.GetCurrentWeaponScript().GetFixer(ai.Transform.name, WeaponFixerTypes.LeftHandle) ? ai.GetCurrentWeaponScript().GetFixer(ai.Transform.name, WeaponFixerTypes.LeftHandle) : null;

            if (leftHandleOfGun)
            {
                ai.Animator.SetIKPosition(AvatarIKGoal.LeftHand, leftHandleOfGun.transform.position);
                ai.Animator.SetIKRotation(AvatarIKGoal.LeftHand, leftHandleOfGun.transform.rotation);
                ai.Animator.SetIKPositionWeight(AvatarIKGoal.LeftHand, WHandIKProps.lHandAim);
                ai.Animator.SetIKRotationWeight(AvatarIKGoal.LeftHand, WHandIKProps.lHandAim);
            }
        }
        public void SolveLookIKUpdate(AIBrain ai)
        {
            LookIKProps.headAim = Mathf.Lerp(CheckEpsilon(LookIKProps.headAim, headIKTarget), headIKTarget, (headIKTarget == 1 ? LookIKProps.headIKSmooth : LookIKProps.headIKBackSmooth) * Time.deltaTime);

            Vector3 lookPos = Vector3.zero;

            switch (lookAtType)
            {
            case ET.LookAtType.ToCurrentTarget:
                lookPos = ai.GetCurrentTargetPos();
                break;

            case ET.LookAtType.ToPosition:
                lookPos = lookAtPosition;
                break;

            case ET.LookAtType.Forward:
                lookPos = ai.Transform.position + ai.Transform.forward * 5f;
                break;

            default:
                break;
            }

            LookIKProps.midPos = ai.Transform.position + Vector3.up * LookIKProps.lookStartHeight;
            Vector3 mPosToTDir = -LookIKProps.midPos + new Vector3(lookPos.x, LookIKProps.midPos.y, lookPos.z);
            Vector3 mPosToCDir = LookIKProps.midPos.y * (Quaternion.AngleAxis(LookIKProps.tAngle, Vector3.up) * ai.Transform.TransformDirection(Vector3.forward));

            Vector3 mPosToZeroDir = LookIKProps.midPos.y * (Quaternion.AngleAxis(0, Vector3.up) * ai.Transform.TransformDirection(Vector3.forward));

            //Debug.DrawRay(LookIKProps.midPos, mPosToCDir * LookIKProps.fwSize, Color.red);
            float cAngleBw = Vector3.Angle(mPosToTDir, mPosToZeroDir);

            cAngleBw = cAngleBw * Mathf.Sign(Vector3.Dot(Quaternion.AngleAxis(90, Vector3.up) * mPosToZeroDir, mPosToTDir));

            float aimingAnglePlus = 0f, weaponBodyBob = 0;

            if (ai.GetStateSystem <AIShooterStateSystemWeapon>() != null /*&& ai.WorldState.GetValue(DictionaryStrings.weaponAimed) == true.ToString()*/ && ai.HaveCurrentWeapon())
            {
                aimingAnglePlus = ai.GetCurrentWeaponScript().bodyFixRight *LookIKProps.aimingWeaponHorFixMultiplier;
                weaponBodyBob   = ai.GetStateSystem <AIShooterStateSystemWeapon>().weaponBodyBob;
            }
            if (headIKTarget == 0)
            {
                LookIKProps.tAngle = Mathf.Lerp(LookIKProps.tAngle, 0, Time.deltaTime * LookIKProps.tAngleLerpBackSpeed);
            }
            else
            {
                LookIKProps.tAngle = Mathf.Lerp(LookIKProps.tAngle, cAngleBw + aimingAnglePlus + weaponBodyBob * LookIKProps.aiWeaponBodyBobMultiplier, Time.deltaTime * LookIKProps.tAngleLerpSpeed);
            }
            LookIKProps.tAngle = Mathf.Clamp(LookIKProps.tAngle, -LookIKProps.maxLookTAngle, LookIKProps.maxLookTAngle);

            LookIKProps.realLookPos = LookIKProps.midPos + mPosToCDir.normalized * LookIKProps.fwSize;
        }
示例#7
0
        public override void AimWeapon(AIBrain ai, bool _hipFire = false)
        {
            ai.stateSystemAnimator.AnimateBool(
                ai, "Aim", true, true, false, "", "ReadyIdle", 1
                );

            ai.stateSystemAnimator.EnableLayer(ai, 1, true, false);

            rightHandTarget = 1;
            leftHandTarget  = 1;
            if (!_hipFire)
            {
                WeaponIK.localPosition = ai.GetCurrentWeaponScript().GetFixer(ai.Transform.name, WeaponFixerTypes.AimSight).localPosition;
                WeaponIK.localRotation = ai.GetCurrentWeaponScript().GetFixer(ai.Transform.name, WeaponFixerTypes.AimSight).localRotation;
            }
            else
            {
                WeaponIK.localPosition = ai.GetCurrentWeaponScript().GetFixer(ai.Transform.name, WeaponFixerTypes.AimHipFire).localPosition;
                WeaponIK.localRotation = ai.GetCurrentWeaponScript().GetFixer(ai.Transform.name, WeaponFixerTypes.AimHipFire).localRotation;
            }
        }
示例#8
0
        public override bool HaveAmmoOnClip(AIBrain ai)
        {
            GunAtt gunAtt = ai.GetCurrentWeaponScript();

            if (!gunAtt)
            {
#if UNITY_EDITOR
                Debug.Log("No GunAtt script is attached to weapon");
                return(false);
#endif
            }

            return(gunAtt.currentClipCapacity > 0);
        }
示例#9
0
        virtual public void OnNewClipOffLeftHand(AIBrain ai)
        {
            // new clip goes to weapon
            if (tempNewClip)
            {
                GunAtt gunAtt = ai.GetCurrentWeaponScript();

                tempNewClip.SetParent(gunAtt.transform);
                tempNewClip.localPosition = gunAtt.clipDefLocalPos;
                tempNewClip.localRotation = gunAtt.clipDefLocalRot;

                gunAtt.curClipObject = tempNewClip;
            }
            tempNewClip = null;
        }
示例#10
0
        virtual public void OnIsHandOnGun(AIBrain ai)
        {
            GunAtt gunAtt = ai.GetCurrentWeaponScript();

            if (RightHandHold && ai.HaveCurrentWeapon() && gunAtt &&
                gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AnimRightHand))
            {
                RightHandHold.localPosition = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AnimRightHand).localPosition;
                RightHandHold.localRotation = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AnimRightHand).localRotation;

                WeaponIK.localPosition = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AimHipFire).localPosition;
                WeaponIK.localRotation = gunAtt.GetFixer(ai.Transform.name, WeaponFixerTypes.AimHipFire).localRotation;
            }

            ai.CurrentWeapon.SetParent(RightHandHold, false);
            ai.CurrentWeapon.localPosition = Vector3.zero;
            ai.CurrentWeapon.localRotation = Quaternion.identity;
        }
示例#11
0
        private void HandleWeaponHandsUpdate(AIBrain ai)
        {
            GunAtt gunAtt = ai.GetCurrentWeaponScript();

            if (gunAtt)
            {
                Vector3 targetLocalPos = target.localPosition;
                float   spreadZ        = (Mathf.Abs(target.localPosition.x) + Mathf.Abs(target.localPosition.y)) * randomTwistSign * WHandIKProps.weaponSpreadAgentMultipliers.z;
                WHandIKProps.weaponSpread = Quaternion.Euler(new Vector3(-targetLocalPos.x * gunAtt.spreadAxisMultipliers.x * WHandIKProps.weaponSpreadAgentMultipliers.x, -targetLocalPos.y * gunAtt.spreadAxisMultipliers.y * WHandIKProps.weaponSpreadAgentMultipliers.y, spreadZ * gunAtt.spreadAxisMultipliers.z));

                WHandIKProps.rHandAim = Mathf.Lerp(CheckEpsilon(WHandIKProps.rHandAim, rightHandTarget), rightHandTarget,
                                                   (rightHandTarget == 1 ? WHandIKProps.rightHandSmooth : WHandIKProps.rightHandBackSmooth) * Time.deltaTime);
                WHandIKProps.rHandAimRot = Mathf.Lerp(CheckEpsilon(WHandIKProps.rHandAimRot, rightHandTarget), rightHandTarget,
                                                      (rightHandTarget == 1 ? WHandIKProps.rightHandSmooth : WHandIKProps.rightHandBackSmooth) * Time.deltaTime);

                WHandIKProps.lHandAim = Mathf.Lerp(CheckEpsilon(WHandIKProps.lHandAim, leftHandTarget), leftHandTarget, Time.deltaTime * (leftHandTarget == 1 ? WHandIKProps.leftHandSmooth : WHandIKProps.leftHandBackSmooth));
            }
        }
示例#12
0
        public override void StartFiring(AIBrain ai)
        {
            GunAtt gunAtt = ai.GetCurrentWeaponScript();

#if UNITY_EDITOR
            if (!gunAtt)
            {
                Debug.Log("No GunAtt script is attached to weapon");
                return;
            }
#endif
            randShotCountI = Mathf.Max(1,
                                       (int)(.1f * gunAtt.maxClipCapacity *
                                             ((int)Random.Range((fireProps.randShotCount.x *
                                                                 fireProps.randShotCountAgentMultiplier.x), (fireProps.randShotCount.y * fireProps.randShotCountAgentMultiplier.y)))));

            randWaitTimerF = -1f;
            isFiring       = true;
        }
示例#13
0
        private void FireWithTimer(AIBrain ai)
        {
            if (isFiring)
            {
                GunAtt gunAtt = ai.GetCurrentWeaponScript();
#if UNITY_EDITOR
                if (!gunAtt)
                {
                    Debug.Log("No GunAtt script is attached to weapon");
                    return;
                }
#endif
                if (ai.InfoCurrentTarget != null && ai.InfoCurrentTarget.GetFireToPosition() != Vector3.zero)
                {
                    fireTo = ai.InfoCurrentTarget.GetFireToPosition();
                }
                if (randWaitTimerF < 0 && randShotCountI > 0 && nextFireTimer < 0)
                {
                    float bBob = 0;

                    Vector3    fw = weaponIKParent.forward;
                    Vector3    to = (-weaponIKParent.position + target.position).normalized;
                    Quaternion xQ = Quaternion.FromToRotation(fw, to);

                    gunAtt.Fire(ai.Transform, target, fireTo, ref bBob, ref randomTwistSign, xQ, fireProps.rayCBulletLayerMask);
                    //bBob = Mathf.Sign(target.localPosition.x) * bBob;
                    weaponBodyBob += bBob;
                    nextFireTimer  = 1;
                    randShotCountI--;
                }
                if (randShotCountI <= 0)
                {
                    randShotCountI = Mathf.Max(1, (int)(.1f * gunAtt.maxClipCapacity *
                                                        (Random.Range((fireProps.randShotCount.x * fireProps.randShotCountAgentMultiplier.x),
                                                                      (fireProps.randShotCount.y * fireProps.randShotCountAgentMultiplier.y)))));
                    randWaitTimerF = Random.Range(fireProps.randWaitTimer.x, fireProps.randWaitTimer.y);
                }
                randWaitTimerF -= Time.deltaTime;
                nextFireTimer  -= Time.deltaTime * gunAtt.fireSpeed;
            }
        }
    public override void OnUpdate(ref bool needToReplan, ref bool needToReevaluateGoals, AIBrain ai)
    {
        GunAtt gunAtt = ai.GetCurrentWeaponScript();

        if (gunAtt != null)
        {
            if (gunAtt.currentClipCapacity <= 0)
            {
                ai.WorldState.SetKey(DS.weaponLoaded, false);
            }
            else
            {
                ai.WorldState.SetKey(DS.weaponLoaded, true);
            }
        }
        else
        {
            ai.WorldState.SetKey(DS.weaponLoaded, true);
        }

        // AI is considered to always has ammo for now
        ai.WorldState.SetKey(DS.haveAmmo, true);
    }
示例#15
0
 public override void ArmWeapon(AIBrain ai)
 {
     ai.stateSystemAnimator.AnimateInteger(
         ai, "Draw", ai.GetCurrentWeaponScript().gunStyle, true, false, "", "LowIdle", 1);
 }
示例#16
0
 virtual public void OnReloadDone(AIBrain ai)
 {
     ai.GetCurrentWeaponScript().currentClipCapacity = ai.GetCurrentWeaponScript().maxClipCapacity;
 }