/// <summary> /// Makes the object move around randomly /// </summary> private void FumbleAround() { _fumbleCurrentWaitTime -= Time.deltaTime; //Fumbling if (_fumbleFly) { if (Math.Sign(_flyDirection.x) != Enemy.Flippable.DirectionSign) { Enemy.Flippable.Flip(); } Enemy.Rigidbody.velocity = _flyDirection * Commons.GetEffectValue(FlyingSpeed, EffectValueType.EnemySpeed); } //Stationary else { Enemy.Rigidbody.velocity = default; } //Choose a new action if (_fumbleCurrentWaitTime <= 0) { _flyDirection = Random.insideUnitCircle.normalized; _fumbleFly = !_fumbleFly; _fumbleCurrentWaitTime = Commons.GetEffectValue(FumbleWaitTime.Pick(), EffectValueType.EnemyWaitTime); } }
/// <summary> /// Makes the object move around randomly /// </summary> private void FumbleAround() { _fumbleCurrentWaitTime -= Time.deltaTime; //Fumbling if (_fumbleWalk) { Enemy.Rigidbody.SetVelocityX(Enemy.Flippable.DirectionSign * Commons.GetEffectValue(WalkSpeed, EffectValueType.EnemySpeed)); } //Stationary else { Enemy.Rigidbody.SetVelocityX(0f); } //Choose a new action if (_fumbleCurrentWaitTime <= 0) { if (!_fumbleWalk && Random.Range(0, 2) == 0) { Enemy.Flippable.Flip(); } _fumbleWalk = !_fumbleWalk; _fumbleCurrentWaitTime = Commons.GetEffectValue(FumbleWaitTime.Pick(), EffectValueType.EnemyWaitTime); } }
/// <summary> /// Creates an explosion with at particle count determined by the provided argument /// </summary> public void Explode(int particleCount) { if (Time.unscaledTime - _lastExplosionTime < 0.5f) { return; } _lastExplosionTime = Time.unscaledTime; for (int i = 0; i < particleCount; i++) { var particle = Commons.InstantiateInCurrentLevel(Particles[Random.Range(0, Particles.Count)], transform.position); particle.velocity = Random.insideUnitSphere * TorqueForce.Pick(); particle.SetVelocityY(currentY => Mathf.Abs(currentY)); particle.AddTorque(TorqueForce.Pick()); } }
/// <summary> /// Creates a weapon instance from the template /// </summary> /// <returns></returns> public virtual WeaponInstance CreateWeaponInstance() { WeaponInstance weapon = new WeaponInstance() { Template = this, MaxDurability = (int)MaxDurability.Pick(), BaseDamage = (int)BaseDamage.Pick(), Range = Range.Pick() }; weapon.Durability = weapon.MaxDurability; return(weapon); }
/// <summary> /// Makes the object jump around randomly /// </summary> private void FumbleAround() { //all decisions are made while grounded. Return if not. if (!grounded) { return; } //if the enemy has waited enough if (_groundTimeLeft <= 0f) { if (_fumbleJumpsLeft > 0) { //jump the direction the enemy is facing JumpToSign(Enemy.Flippable.DirectionSign); } else { //resets all counters _groundTimeLeft = Commons.GetEffectValue(GroundTime.Pick(), EffectValueType.EnemyWaitTime); _fumbleJumpsLeft = FumbleJumps.PickInt() + 1; _flipTime = _groundTimeLeft / 2; } } //wait more else { _groundTimeLeft -= Time.deltaTime; //halfway through the waiting: 50/50 chance of changing direction if (_groundTimeLeft < _flipTime) { if (Random.Range(0, 2) == 0) { Enemy.Flippable.Flip(); } _flipTime = -5; } } }