예제 #1
0
        IEnumerator BeamRoutine()
        {
            float   timeShot = Time.time;
            Vector3 shootP   = shootPoint.position;

            while (!hit)
            {
                if (target != null)
                {
                    targetPos = target.GetTargetT().position;
                }
                if (shootPoint != null)
                {
                    shootP = shootPoint.position;
                }

                float   dist           = Vector3.Distance(shootP, targetPos);
                Ray     ray            = new Ray(shootP, (targetPos - shootP));
                Vector3 targetPosition = ray.GetPoint(dist - hitThreshold);

                for (int i = 0; i < lineList.Count; i++)
                {
                    lineList[i].SetPosition(0, shootP);
                    lineList[i].SetPosition(1, targetPosition);
                }

                if (Time.time - timeShot > beamDuration)
                {
                    Hit();
                    break;
                }

                yield return(null);
            }
        }
예제 #2
0
        public void Shoot(AttackInstance attInst=null, Transform sp=null)
        {
            if(attInst==null || attInst.tgtUnit==null){
                ObjectPoolManager.Unspawn(thisObj);
                return;
            }

            attInstance=attInst;
            target=attInstance.tgtUnit;
            targetPos=target.GetTargetT().position;
            hitThreshold=Mathf.Max(0.1f, target.hitThreshold);

            shootPoint=sp;
            if(shootPoint!=null) thisT.rotation=shootPoint.rotation;
            shootPointPos=shootPoint!=null ? shootPoint.position : thisT.position ;

            if(shootEffect!=null) ObjectPoolManager.Spawn(shootEffect, thisT.position, thisT.rotation);

            hit=false;

            if(type==_ShootObjectType.Projectile) StartCoroutine(ProjectileRoutine());
            if(type==_ShootObjectType.Beam) StartCoroutine(BeamRoutine());
            if(type==_ShootObjectType.Missile) StartCoroutine(MissileRoutine());
            if(type==_ShootObjectType.Effect) StartCoroutine(EffectRoutine());
        }
예제 #3
0
        IEnumerator BeamRoutine()
        {
            float timeShot = Time.time;

            while (!hit)
            {
                if (target != null)
                {
                    targetPos = target.GetTargetT().position;
                }

                float   dist           = Vector3.Distance(shootPoint.position, targetPos);
                Ray     ray            = new Ray(shootPoint.position, (targetPos - shootPoint.position));
                Vector3 targetPosition = ray.GetPoint(dist - hitThreshold);

                Vector3   _temp;
                int       _count;
                Vector3   _offset;
                Vector3[] _position;
                for (int i = 0; i < lineList.Count; i++)
                {
                    _temp   = targetPosition - shootPoint.position;
                    _count  = (int)(dist / 0.2) + 2;
                    _offset = _temp / _count;
                    lineList[i].numPositions = _count;
                    _position    = new Vector3[_count];
                    _position[0] = shootPoint.position;
                    for (int j = 1; j < (_count - 1); j++)
                    {
                        Vector3 _pos = new Vector3(shootPoint.position.x + j * _offset.x, shootPoint.position.y + j * _offset.y, shootPoint.position.z + j * _offset.z + Random.Range(-0.2f, 0.2f));
                        _position[j] = _pos;
                    }
                    _position[_count - 1] = targetPosition;
                    lineList[i].SetPositions(_position);
                }

                if (Time.time - timeShot > beamDuration)
                {
                    Hit();
                    break;
                }

                yield return(null);
            }
        }
예제 #4
0
        public virtual void FixedUpdate()
        {
            if (regenHPBuff != 0)
            {
                HP += regenHPBuff * Time.fixedDeltaTime;
                HP  = Mathf.Clamp(HP, 0, GetFullHP());
            }

            if (HPRegenRate > 0 && currentHPStagger <= 0)
            {
                HP += GetHPRegenRate() * Time.fixedDeltaTime;
                HP  = Mathf.Clamp(HP, 0, GetFullHP());
            }
            if (defaultShield > 0 && shieldRegenRate > 0 && currentShieldStagger <= 0)
            {
                shield += GetShieldRegenRate() * Time.fixedDeltaTime;
                shield  = Mathf.Clamp(shield, 0, GetFullShield());
            }

            currentHPStagger     -= Time.fixedDeltaTime;
            currentShieldStagger -= Time.fixedDeltaTime;


            if (target != null && !IsInConstruction() && !stunned)
            {
                if (turretObject != null)
                {
                    if (rotateTurretAimInXAxis && barrelObject != null)
                    {
                        Vector3 targetPos = target.GetTargetT().position;
                        Vector3 dummyPos  = targetPos;
                        dummyPos.y = turretObject.position.y;

                        Quaternion wantedRot = Quaternion.LookRotation(dummyPos - turretObject.position);
                        turretObject.rotation = Quaternion.Slerp(turretObject.rotation, wantedRot, turretRotateSpeed * Time.deltaTime);

                        float angle      = Quaternion.LookRotation(targetPos - barrelObject.position).eulerAngles.x;
                        float distFactor = Mathf.Min(1, Vector3.Distance(turretObject.position, targetPos) / GetSOMaxRange());
                        float offset     = distFactor * GetSOMaxAngle();
                        wantedRot = turretObject.rotation * Quaternion.Euler(angle - offset, 0, 0);

                        barrelObject.rotation = Quaternion.Slerp(barrelObject.rotation, wantedRot, turretRotateSpeed * Time.deltaTime);

                        if (Quaternion.Angle(barrelObject.rotation, wantedRot) < aimTolerance)
                        {
                            targetInLOS = true;
                        }
                        else
                        {
                            targetInLOS = false;
                        }
                    }
                    else
                    {
                        Vector3 targetPos = target.GetTargetT().position;
                        if (!rotateTurretAimInXAxis)
                        {
                            targetPos.y = turretObject.position.y;
                        }

                        Quaternion wantedRot = Quaternion.LookRotation(targetPos - turretObject.position);
                        if (rotateTurretAimInXAxis)
                        {
                            float distFactor = Mathf.Min(1, Vector3.Distance(turretObject.position, targetPos) / GetSOMaxRange());
                            float offset     = distFactor * GetSOMaxAngle();
                            wantedRot *= Quaternion.Euler(-offset, 0, 0);
                        }
                        turretObject.rotation = Quaternion.Slerp(turretObject.rotation, wantedRot, turretRotateSpeed * Time.deltaTime);

                        if (Quaternion.Angle(turretObject.rotation, wantedRot) < aimTolerance)
                        {
                            targetInLOS = true;
                        }
                        else
                        {
                            targetInLOS = false;
                        }
                    }
                }
                else
                {
                    targetInLOS = true;
                }
            }

            //rotate turret back to origin
            if (IsCreep() && target == null && turretObject != null && !stunned)
            {
                turretObject.localRotation = Quaternion.Slerp(turretObject.localRotation, Quaternion.identity, turretRotateSpeed * Time.deltaTime * 0.25f);
            }
        }