void UpdateDirection() { if (follow != null && follow as UnityEngine.Object != null) { Vector3 targetFollow = follow.center; Vector2 Direct2 = (targetFollow - transform.position).normalized; float zx = MathQ.DirectionToRotation(Direct2).z; float zc = MathQ.DirectionToRotation(damage.Direction).z; float zz; float z = SpeedRotate * 360 * Time.deltaTime; if (!isLeft(damage.Direction, follow.center)) { zz = zc - z; } else { zz = zc + z; } if ((zz - zx) * (zc - zx) <= 0) { zz = zx; } damage.Direction = MathQ.RotationToDirection(zz); } }
protected virtual Vector3 GiatSung(Vector3 direction) { Vector3 Do = MathQ.DirectionToRotation(direction); Do += new Vector3(0, 0, Random.Range(-DoGiat / 2, DoGiat / 2)); return(MathQ.RotationToDirection(Do.z).normalized); }
public void SetUp(Entity e1, Entity e2) { if (line != null) { line.gameObject.SetActive(true); line.startWidth = 0; line.endWidth = 0; Vector3[] a = GetPos(Vector2.Distance(e1.center, e2.center)).ToArray(); line.positionCount = a.Length; line.SetPositions(a); if (render1 != null) { render1.enabled = true; render1.transform.localPosition = Vector3.zero; render1.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, Random.Range(0, 360))); } if (render2 != null) { render2.enabled = true; render2.transform.localPosition = a[a.Length - 1]; render2.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, Random.Range(0, 360))); } transform.position = e1.center; transform.rotation = Quaternion.Euler(MathQ.DirectionToRotation((e2.center - e1.center).normalized)); StartCoroutine(UpdateSize(0.3f)); } else { Destroy(gameObject); return; } }
protected Vector3 GetRotationByDirection(Vector3 Direction) { if (Direction.x < 0) { Direction.x = -Direction.x; Direction.y = -Direction.y; } return(MathQ.DirectionToRotation(Direction)); }
protected Vector2 getRotationToPlayer(Vector2 dir, int offset) { if (offset < 0) { offset = -offset; } offset = offset % 90; Vector3 Do = MathQ.DirectionToRotation(dir); Do += new Vector3(0, 0, Random.Range(-offset, offset)); return(MathQ.RotationToDirection(Do.z).normalized); }
protected virtual void OnBeginAttack() { float z = MathQ.DirectionToRotation(DirectFire).z; for (int i = -1; i <= 1; i++) { Vector2 dirAttack = MathQ.RotationToDirection(z + OffsetAngleAttack * i); BulletEnemy bullet = pool.Spawn(id_bul, PositionSpawnBullet, MathQ.DirectionToQuaternion(dirAttack)) as BulletEnemy; DamageData dam = new DamageData(); SetUpDamageData(dam); dam.Direction = dirAttack; bullet.StartUp(dam); } SetNewAction(Action.Idle); OnBeginIdle(); }
public override void Shoot(DamageData damageData) { base.Shoot(damageData); for (int i = -1; i <= 1; i += 2) { int am = (int)Random.Range(RangeAmount.x, RangeAmount.y + 1); for (int j = 0; j < am; j++) { int dolec = i * (Random.Range(OffsetA, OffsetB + 1)); Vector3 DirShoot = damageData.Direction; float z = MathQ.DirectionToRotation(DirShoot).z; z += dolec; DirShoot = MathQ.RotationToDirection(z); SetUpDamageDataExtra(damageData, DirShoot); BulletBase bullet = pool.Spawn(id_pool_bullet_extra, PositionStartAttack, Quaternion.identity) as BulletBase; bullet.StartUp(damageData); } } }
public virtual void SpawnBui(DamageData damage) { if (pooling == null) { Debug.Log("Dust need Prefab"); } Vector3 DirZ = MathQ.DirectionToRotation(damage.Direction); int Amount = damage.Damage / 2 * MutiDus; float Off = 15; for (int i = 0; i < Amount; i++) { Vector3 pos = new Vector3(Random.Range(-RangeSpawn.x, RangeSpawn.x), Random.Range(-RangeSpawn.y, RangeSpawn.y), 0) + Offset; Vector3 dir = MathQ.RotationToDirection(DirZ.z + Random.Range(-Off, Off)); pos = transform.TransformPoint(pos); (pooling.Spawn(id_dust, pos, MathQ.DirectionToQuaternion(new Vector3(0, 0, Random.Range(0, 360)))) as Dust) .SetUp(1, dir, Random.Range(RangeSpeed.x, RangeSpeed.y), Random.Range(RangeSize.x, RangeSize.y), color); } }
private void Attacking2() { float startAngle = MathQ.DirectionToRotation(DirectFire).z - 20; startAngle = startAngle < -180 ? startAngle + 360 : startAngle; for (int i = 0; i < 2; i++) { float angle = startAngle + i * 20; if (angle >= 180) { angle -= 360; } Vector3 Direction = MathQ.RotationToDirection(angle); DamageData damage = new DamageData(); SetUpDamageData(damage); damage.Direction = Direction; BulletFollow bul = pool.Spawn(id_bull, positionSpawnBullet, MathQ.DirectionToQuaternion(Direction)) as BulletFollow; bul.SetTarget(Find.FindTargetNearest(center, 7f, targetFolow)); bul.StartUp(damage); } }
protected override Vector3 GiatSung(Vector3 direction) { if (nextAmountbullet == 1) { return(base.GiatSung(direction)); } else { if (vitriTren) { if (isLeftDir) { Vector3 Do = MathQ.DirectionToRotation(direction); Do += new Vector3(0, 0, Random.Range(-DoGiat / 2, 0)); return(MathQ.RotationToDirection(Do.z).normalized); } else { Vector3 Do = MathQ.DirectionToRotation(direction); Do += new Vector3(0, 0, Random.Range(0, DoGiat / 2)); return(MathQ.RotationToDirection(Do.z).normalized); } } else { if (isLeftDir) { Vector3 Do = MathQ.DirectionToRotation(direction); Do += new Vector3(0, 0, Random.Range(0, DoGiat / 2)); return(MathQ.RotationToDirection(Do.z).normalized); } else { Vector3 Do = MathQ.DirectionToRotation(direction); Do += new Vector3(0, 0, Random.Range(-DoGiat / 2, 0)); return(MathQ.RotationToDirection(Do.z).normalized); } } } }
private void Spawn() { if (pooling == null) { return; } float startAngle = MathQ.DirectionToRotation(damage.Direction).z + Random.Range(0, 360 / AmountBulletExtra); for (int i = 0; i < AmountBulletExtra; i++) { DamageData damage = this.damage.Clone; float angle = startAngle + 360 / AmountBulletExtra * i; if (angle > 180) { angle -= 360; } Vector3 dir = MathQ.RotationToDirection(angle); damage.Direction = dir; BulletExtraBoring bull = pooling.Spawn(id_pooling, transform.position, Quaternion.identity) as BulletExtraBoring; bull.StartUp(damage); bull.skipGameobject = targetHit; } }
void Spawn() { if (bulletPrefab == null || !spawning) { return; } float z = Random.Range(0, 360 / Amount); for (int i = 0; i < Amount; i++) { float newZ = z + 360 * i / Amount; if (newZ > 180) { newZ -= 360; } Vector3 dir = MathQ.RotationToDirection(newZ); BulletBase bul = pool.Spawn(id_bul, GetPositionSpawn(dir), Quaternion.Euler(MathQ.DirectionToRotation(dir)), null) as BulletBase; DamageData damage = SetUpDamageData(); damage.Direction = dir; bul.StartUp(damage); } }