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); }
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); }
protected override void OnOutBounds() { if (CalcObject.IsOutBounds(transform)) { Destroy(packet); } }
protected virtual void OnOutBounds() { if (CalcObject.IsOutBounds(transform)) { RePoolOrDestroy(); } }
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; } }
private void resetLinearAngle() { if (!resetSwitch && assigned) { float angle = CalcObject.AngleBetweenVectors(transform.position, lastKnownPos); Trajectory = CalcObject.RotationToShotVector(angle); resetSwitch = true; } }
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); } } }
private void burst() { burstTimer.Run(BurstFrequency); if (burstTimer.Flag) { body.AddForce(CalcObject.RotationToShotVector(transform.rotation.eulerAngles.z) * ShotSpeed / 5, ForceMode2D.Impulse); } burstFlag = burstTimer.Flag; }
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); }
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); } } }
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); }
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); }