Esempio n. 1
0
        void WhenAssisting()
        {
            Vector3 TargetDirection;
            Vector3 LocalTargetDirection = targetPoint;

            /*if (this.transform.InverseTransformPoint(targetPoint).sqrMagnitude <= 25 && DroneAIType.Value == 1)
             * {
             *  targetPoint = MyControl.PleaseGiveMeNewOrbitPoint(this.transform.position, this.rigidBody.velocity.normalized, false);
             *
             *  RaycastHit[] rhs = Physics.RaycastAll(
             *       new Ray(this.transform.position, this.transform.InverseTransformPoint(MyControl.transform.TransformPoint(targetPoint))),
             *       (MyControl.transform.TransformPoint(targetPoint) - this.transform.position).magnitude);
             *  if (rhs.Length != 0
             *      )
             *  {
             *      foreach (RaycastHit RH in rhs)
             *      {
             *          if (!RH.collider.isTrigger)
             *          {
             *              targetPoint = MyControl.PleaseGiveMeNewOrbitPoint(this.transform.position, this.rigidBody.velocity.normalized, true);
             *              return;
             *          }
             *      }
             *  }
             * }*/

            Vector3 LocalForwardOrRight;

            if (IncomingVectors.Length != 0 && !IgnoreIncoming)
            {
                LocalForwardOrRight = this.transform.forward;

                LocalTargetDirection = this.transform.TransformPoint(-RelativeAverageOfPoints(IncomingVectors, SphereSize));
                IncomingVectors      = new Vector3[0];
                PositionIndicator.transform.position = this.transform.TransformPoint(LocalTargetDirection);

                TargetDirection           = (getCorrTorque(LocalForwardOrRight, LocalTargetDirection - this.transform.position * 1, rigidBody, 0.01f * size) * Mathf.Rad2Deg).normalized;
                rigidBody.angularVelocity = (TargetDirection * RotatingSpeed);
            }
            else if (currentTarget != null)
            {
                LocalForwardOrRight = this.transform.forward;
                if (currentTarget.GetComponent <Rigidbody>() && currentTarget.transform.position != this.transform.position)
                {
                    LocalTargetDirection = currentTarget.transform.position;
                    targetPoint          = currentTarget.transform.position;
                    PositionIndicator.transform.position = targetPoint;

                    LocalTargetDirection = currentTarget.transform.position;
                    LocalTargetDirection = DroneDirectionIndicator(currentTarget.transform.position, 炮弹速度 + this.rigidBody.velocity.magnitude);

                    TargetDirection = (getCorrTorque(LocalForwardOrRight, LocalTargetDirection - this.transform.position * 1, this.GetComponent <Rigidbody>(), 0.01f * size) * Mathf.Rad2Deg).normalized;

                    GetComponent <Rigidbody>().angularVelocity = (TargetDirection * RotatingSpeed);

                    if (
                        FUcounter % 30 == 0 &&
                        Vector3.Angle(transform.forward, LocalTargetDirection - this.transform.position * 1) < 15 &&
                        SqrDistanceToControl() >= Mathf.Pow(MyControl.OrbitRadius.Value * 2, 2)
                        )
                    {
                        CB.Shoot();
                        //CB.alreadyShot = false;
                        int i = 1;
                        CB.OnReloadAmmo(ref i, AmmoType.Cannon, true, false);
                    }
                }
            }
            else// if (IAmEscapingOrReturning)
            {
                //LocalTargetDirection = DroneDirectionIndicator(MyControl.transform.TransformPoint(targetPoint), this.rigidBody.velocity.magnitude);
                PositionIndicator.transform.position = MyControl.transform.position;

                LocalTargetDirection = DroneDirectionIndicator(MyControl.transform.position, 0);

                ChasingControl = SqrDistanceToControl() >= Mathf.Pow(MyControl.OrbitRadius.Value, 2);
                Debug.Log(SqrDistanceToControl() + "," + Mathf.Pow(MyControl.OrbitRadius.Value, 2));

                LocalForwardOrRight =
                    ChasingControl ?
                    LocalForwardOrRight = this.transform.forward :
                                          LocalForwardOrRight = this.transform.right;

                Vector3 TheShouldbeHeight = this.transform.InverseTransformPoint(new Vector3(rigidBody.velocity.x, MyControl.transform.position.y, rigidBody.velocity.z));

                TargetDirection  = (getCorrTorque(LocalForwardOrRight, LocalTargetDirection - this.transform.position * 1, this.GetComponent <Rigidbody>(), 0.01f * size) * Mathf.Rad2Deg).normalized;
                TargetDirection += (getCorrTorque(TheShouldbeHeight, LocalTargetDirection - this.transform.position * 1, this.GetComponent <Rigidbody>(), 0.01f * size) * Mathf.Rad2Deg).normalized;

                foreach (RaycastHit RH in Physics.RaycastAll(this.transform.position, targetPoint, targetPoint.magnitude))
                {
                    if (!RH.collider.isTrigger)
                    {
                        LocalTargetDirection = DroneDirectionIndicator(new Vector3(targetPoint.x, this.transform.position.y, targetPoint.z), this.rigidBody.velocity.magnitude);
                        break;
                    }
                }
                GetComponent <Rigidbody>().angularVelocity = (TargetDirection * RotatingSpeed);
            }

            float MinThings;

            if (currentTarget == null)
            {
                if (this.transform.position.y >= MyControl.transform.position.y && SqrDistanceToControl() <= Mathf.Pow(MyControl.OrbitRadius.Value, 2) && (LocalForwardOrRight - this.transform.forward).sqrMagnitude <= 0.01f)
                {
                    MinThings  = (Math.Abs(Vector3.Angle(LocalForwardOrRight, LocalTargetDirection - this.transform.position * 1))) * 38 / 180;
                    MinThings -= 38 / 2;
                }
                else
                {
                    MinThings = 38;
                }
                ///AAA
                MinThings = 38;

                if (!ChasingControl && Vector3.Angle(transform.right, LocalTargetDirection - this.transform.position * 1) > 15)
                {
                    OrbitVeloMultiplier = Math.Max(0.1f, OrbitVeloMultiplier - 0.01f);
                }
                if (Vector3.Angle(transform.forward, Vector3.up) < 60 && rigidBody.velocity.y < 10)
                {
                    OrbitVeloMultiplier = Math.Min(1.1f, OrbitVeloMultiplier + 0.02f);
                }
                //if(SqrDistanceToControl() >= Mathf.Pow(MyControl.OrbitRadius.Value, 2))
                //{
                //    OrbitVeloMultiplier = 1;
                //}
            }
            else
            {
                MinThings           = (180 - Math.Abs(Vector3.Angle(LocalForwardOrRight, LocalTargetDirection - this.transform.position * 1))) * 38 / 180;
                OrbitVeloMultiplier = 1;
            }
            if (this.rigidBody.velocity.sqrMagnitude <= 5 * 5 * 58 * 58)
            {
                Rigidbody.AddRelativeForce(
                    Vector3.forward * Mathf.Min(
                        38,
                        MinThings
                        ) * this.Rigidbody.mass * OrbitVeloMultiplier
                    );            //Need calculate size
            }
        }
        protected override IEnumerator Shoot()
        {
            ShootEnabled = false;
            float randomDelay = 0f;

            if (CB.boltObject.gameObject.activeSelf == false)
            {
                if (EnhancementEnabled)
                {
                    if (bullet.Custom)
                    {
                        StartCoroutine(shoot(bullet.bulletObject));
                    }
                    else
                    {
                        StartCoroutine(shoot(CB.boltObject.gameObject));
                    }
                }
                else
                {
                    StartCoroutine(shoot(CB.boltObject.gameObject));
                }
            }
            else
            {
                if (EnhancementEnabled)
                {
                    if (bullet.Custom)
                    {
                        StartCoroutine(shoot(bullet.bulletObject));
                    }
                    else
                    {
                        StartCoroutine(shoot());
                    }
                }
            }

            yield return(new WaitForSeconds(IntervalSlider.Value + randomDelay));

            if (StatMaster.GodTools.InfiniteAmmoMode && EnhancementEnabled)
            {
                ShootEnabled = true;
            }
            yield break;

            IEnumerator shoot(GameObject bulletObject = null)
            {
                randomDelay = UnityEngine.Random.Range(0f, RandomDelaySlider.Value);
                yield return(new WaitForSeconds(randomDelay));

                if (bulletObject != null)
                {
                    var go = (GameObject)Instantiate(bulletObject, transform.TransformPoint(CB.boltSpawnPos), CB.boltSpawnRot);
                    go.AddComponent <DelayCollision>().Delay = bullet.DelayCollision;
                    go.SetActive(true);
                    go.GetComponent <Rigidbody>().AddForce(-transform.up * CB.boltSpeed * CB.StrengthSlider.Value);
                }
                if (!firstShoot)
                {
                    CB.Shoot();
                }
                firstShoot = false;
                yield break;
            }
        }
Esempio n. 3
0
        void WhatComputerWillDo()
        {
            Vector3 LocalTargetDirection = targetPoint;

            if (HitPoints <= (this.rigidBody.velocity - targetVeloAveraged).sqrMagnitude)
            {
                IgnoreIncoming = true;
            }

            Vector3 TargetDirection;

            if (IncomingVectors.Length != 0 && !IgnoreIncoming)
            {
                LocalTargetDirection = this.transform.TransformPoint(-RelativeAverageOfPoints(IncomingVectors, SphereSize));
                IncomingVectors      = new Vector3[0];
                PositionIndicator.transform.position = this.transform.TransformPoint(LocalTargetDirection);

                //this.transform.rotation.SetFromToRotation(this.transform.forward, LocalTargetDirection);
                //Vector3 rooo = Vector3.RotateTowards(this.transform.forward, LocalTargetDirection - this.transform.position, RotatingSpeed * size, RotatingSpeed * size);
                //Debug.Log(LocalTargetDirection + "and" + this.transform.up + "and" + rooo);
                //this.transform.rotation = Quaternion.LookRotation(rooo);
                //LocalTargetDirection = new Vector3(LocalTargetDirection.x, LocalTargetDirection.y - this.transform.position.y, LocalTargetDirection.z);
                //float mag = (LocalTargetDirection.normalized - transform.forward.normalized).magnitude;

                TargetDirection = (getCorrTorque(this.transform.forward, LocalTargetDirection - this.transform.position * 1, rigidBody, 0.01f * size) * Mathf.Rad2Deg).normalized;

                rigidBody.angularVelocity = (TargetDirection * RotatingSpeed);
            }
            else if (currentTarget != null)
            {
                if (currentTarget.GetComponent <Rigidbody>() && currentTarget.transform.position != this.transform.position)
                {
                    LocalTargetDirection = currentTarget.transform.position;
                    targetPoint          = currentTarget.transform.position;
                    PositionIndicator.transform.position = targetPoint;


                    LocalTargetDirection = currentTarget.transform.position;
                    LocalTargetDirection = DroneDirectionIndicator(currentTarget.transform.position, 炮弹速度 + this.rigidBody.velocity.magnitude);

                    TargetDirection = (getCorrTorque(this.transform.forward, LocalTargetDirection - this.transform.position * 1, this.GetComponent <Rigidbody>(), 0.01f * size) * Mathf.Rad2Deg).normalized;

                    GetComponent <Rigidbody>().angularVelocity = (TargetDirection * RotatingSpeed);

                    if (FUcounter % 30 == 0 && Vector3.Angle(transform.forward, LocalTargetDirection - this.transform.position * 1) < 15)
                    {
                        CB.Shoot();
                        int i = 1;
                        CB.OnReloadAmmo(ref i, AmmoType.Cannon, true, false);
                        //if (DroneAIType.Value == 1)
                        //{
                        if (!NotEvenHavingAJoint)
                        {
                            if (!currentTarget.GetComponent <ConfigurableJoint>())
                            {
                                currentTarget = null;
                            }
                        }
                        if (!NotEvenHavingAFireTag)
                        {
                            if (currentTarget.GetComponent <FireTag>().burning)
                            {
                                currentTarget = null;
                            }
                        }
                        //}
                        //else
                        //{
                        //    if (currentTarget.GetComponent<EntityAI>())
                        //    {
                        //        if (currentTarget.GetComponent<EntityAI>().isDead == true)
                        //        {
                        //            currentTarget = null;
                        //        }
                        //    }
                        //    else if (currentTarget.GetComponent<EnemyAISimple>())
                        //    {
                        //        if (currentTarget.GetComponent<EnemyAISimple>().isDead == true)
                        //        {
                        //            currentTarget = null;
                        //        }
                        //    }
                        //}
                    }
                }
            }
            else if (IAmEscapingOrReturning)
            {
                LocalTargetDirection = DroneDirectionIndicator(targetPoint, this.rigidBody.velocity.magnitude);
                PositionIndicator.transform.position = targetPoint;
                foreach (RaycastHit RH in Physics.RaycastAll(this.transform.position, targetPoint, targetPoint.magnitude))
                {
                    if (!RH.collider.isTrigger)
                    {
                        LocalTargetDirection = DroneDirectionIndicator(new Vector3(targetPoint.x, this.transform.position.y, targetPoint.z), this.rigidBody.velocity.magnitude);
                        break;
                    }
                }
                TargetDirection = (getCorrTorque(this.transform.forward, LocalTargetDirection - this.transform.position * 1, this.GetComponent <Rigidbody>(), 0.01f * size) * Mathf.Rad2Deg).normalized;

                GetComponent <Rigidbody>().angularVelocity = (TargetDirection * RotatingSpeed);
            }
            else
            {
                IAmSwitching = true;
                TargetSelector();
            }
            if (this.rigidBody.velocity.sqrMagnitude <= 5 * 5 * 58 * 58)
            {
                Rigidbody.AddRelativeForce(
                    Vector3.forward * Mathf.Min(
                        38,
                        (180 - Math.Abs(Vector3.Angle(transform.forward, LocalTargetDirection - this.transform.position * 1))) * 38 / 180) * this.Rigidbody.mass
                    );//Need calculate size
            }
        }