示例#1
0
        private Vector2 angleToPercentage()
        {
            int   globalDirection = (transform.lossyScale.x < 0) ? -1 : 1;
            float angle           = Mathf.Abs(transform.rotation.eulerAngles.z); //absolute value fixes negative value at -360

            return(CalcObject.RotationToShotVector(angle) * globalDirection);
        }
示例#2
0
        public static Vector2 AngleToAddForce(Vector2 from, Vector2 to, float force)
        {
            float   angle = CalcObject.AngleBetweenVectors(from, to);
            Vector3 dir   = Quaternion.AngleAxis(angle, Vector3.forward) * Vector3.right;

            return(dir * force);
        }
示例#3
0
 protected override void OnOutBounds()
 {
     if (CalcObject.IsOutBounds(transform))
     {
         Destroy(packet);
     }
 }
示例#4
0
 protected virtual void OnOutBounds()
 {
     if (CalcObject.IsOutBounds(transform))
     {
         RePoolOrDestroy();
     }
 }
示例#5
0
        private void movement()
        {
            reAngle.RunOnce(ReAngleTime);

            if (reAngle.Flag)
            {
                if (reAngleTriggered)
                {
                    return;
                }

                float angle = Emitter.transform.rotation.eulerAngles.z - vertMod;
                angle += (angle < 0) ? 360 : 0;

                float embellish = Embellish;
                embellish = (angle < 180) ? embellish * -1 : embellish;

                if (Emitter.transform.lossyScale.x < 0)
                {
                    embellish -= 180;
                }

                Trajectory         = CalcObject.RotationToShotVector(embellish + vertMod);
                transform.rotation = Quaternion.AngleAxis(embellish + vertMod, Vector3.forward);

                reAngleTriggered = true;
            }
        }
示例#6
0
 private void resetLinearAngle()
 {
     if (!resetSwitch && assigned)
     {
         float angle = CalcObject.AngleBetweenVectors(transform.position, lastKnownPos);
         Trajectory  = CalcObject.RotationToShotVector(angle);
         resetSwitch = true;
     }
 }
示例#7
0
 private void setRotation(Transform obj, bool trackingEngaged)
 {
     if (obj != null)
     {
         if (trackingEngaged)
         {
             Vector3 vectorToTarget = obj.position - transform.position;
             transform.rotation = CalcObject.VectorToRotationSlerp(transform.rotation, vectorToTarget, TrackRotationSpeed);
         }
     }
 }
示例#8
0
        private void burst()
        {
            burstTimer.Run(BurstFrequency);

            if (burstTimer.Flag)
            {
                body.AddForce(CalcObject.RotationToShotVector(transform.rotation.eulerAngles.z) * ShotSpeed / 5, ForceMode2D.Impulse);
            }

            burstFlag = burstTimer.Flag;
        }
示例#9
0
        void FixedUpdate()
        {
            if (!CenterMassPivot)
            {
                return;
            }

            if (rotationSpeed + rotationSpeedRange > 0)
            {
                Utilities.Warn("WARNING: Rotation Greater Than 0 May Conflict with CenterMassPivot", this.gameObject.name);
            }

            transform.rotation = CalcObject.VectorToRotationSlerp(transform.rotation, body.velocity, PivotRotationSpeed);
        }
示例#10
0
 private void setRotation(bool trackingEngaged)
 {
     if (RotationType == HomingRotation.Tracking)
     {
         if (trackingEngaged)
         {
             Vector3 direction = (Vector2)transform.position - prevShotPos;
             transform.rotation = CalcObject.VectorToRotationSlerp(transform.rotation, direction, TrackRotationSpeed);
         }
         else
         {
             transform.rotation = CalcObject.VectorToRotationSlerp(transform.rotation, Trajectory, TrackRotationSpeed);
         }
     }
 }
示例#11
0
        public override void Start()
        {
            base.Start();

            maxDistance = (CalcObject.getMaxScreenDistance() + AddedMaxDistance) * ppu * globalDirection;

            originGo = initLaserParts(new GameObject("Origin"), new Vector2(0, 0), OriginImg);
            mainGo   = initLaserParts(new GameObject("Main"), new Vector2(originGo.GetComponent <SpriteRenderer>().sprite.bounds.size.x *globalDirection, 0), MainImg);
            tipGo    = initLaserParts(new GameObject("Tip"), new Vector2(0, 0), TipImg);

            originAnim = initAnimations(originGo, OriginImg);
            mainAnim   = initAnimations(mainGo, MainImg);
            blastAnim  = initAnimations(tipGo, BlastImg);
            tipAnim    = initAnimations(tipGo, TipImg);
        }
示例#12
0
        private GameObject initLaserMain(GameObject main, Vector3 initPosition, Sprite[] sprite, int sort)
        {
            main.transform.parent        = this.transform;
            main.transform.localPosition = initPosition;
            main.transform.localScale    = new Vector3(main.transform.localScale.x * globalDirection, main.transform.localScale.y);
            main.transform.rotation      = new Quaternion();

            int chunksNeeded = (int)((CalcObject.getMaxScreenDistance() / MainImg[0].bounds.size.x) + AddedMaxDistance);

            mainAnims = new BasicAnimation[chunksNeeded];

            int startFrame = 0;

            for (int i = 0; i < chunksNeeded; i++)
            {
                GameObject chunk = new GameObject("Chunk" + i);
                chunk.transform.parent        = main.transform;
                chunk.transform.localPosition = new Vector2(sprite[0].bounds.size.x * i, 0);
                chunk.transform.localRotation = new Quaternion();
                chunk.transform.localScale    = new Vector2(1, 1);

                SpriteRenderer chunkSprite = chunk.AddComponent <SpriteRenderer>();
                chunkSprite.sprite           = sprite[startFrame];
                chunkSprite.sortingOrder     = sort + UniqueMaskId;
                chunkSprite.sortingLayerName = sortLayer;
                chunkSprite.color            = FiringScript.SpriteColor;
                chunkSprite.maskInteraction  = SpriteMaskInteraction.VisibleInsideMask;

                mainAnims[i] = new BasicAnimation(ref chunkSprite, ref MainImg, startFrame);

                startFrame++;
                if (!StaggerAnimations || startFrame > sprite.Length - 1)
                {
                    startFrame = 0;
                }
            }

            maxDistance = chunksNeeded * MainImg[0].bounds.size.x * ppu * globalDirection;
            mainMask    = initMask(main, "MainMask", new Vector2(0, 0), new Vector2(1, MainMaskYScale), sortOrder, sortOrder - 1);

            return(main);
        }