public static Vector3 PredictDirection(Vector3 shooterPosition, Vector3 targetPosition, float projectileSpeed, Vector3 targetVelocity)
    {
        float speedRatioSq = projectileSpeed.Sq() / targetVelocity.sqrMagnitude;                                         //vr^2 = vw^2 / vb^2

        targetVelocity.Normalize();                                                                                      //from now on targetVelocity will be nomralized (magnitude == 1)
        Vector3 adjustedPosition = MyMathlib.MultiplyComplexConjugate(shooterPosition - targetPosition, targetVelocity); //dw = (xw,yw)

        if (speedRatioSq == 1f)                                                                                          // Equal velocities, its not a quadratic equation in this case
        {
            return(adjustedPosition.x <= 0f ? targetVelocity :
                   (targetPosition + adjustedPosition.sqrMagnitude / (2f * adjustedPosition.x) * targetVelocity - shooterPosition).normalized);
        }

        float discriminant = speedRatioSq * adjustedPosition.sqrMagnitude - adjustedPosition.y.Sq();  //D = b^2-4ac simplified and divided by 4

        if (speedRatioSq > 1f || (discriminant > 0f && adjustedPosition.x > 0f))
        {
            float xs = (adjustedPosition.x - Mathf.Sqrt(discriminant)) / (1 - speedRatioSq);
            return((targetPosition + xs * targetVelocity - shooterPosition).normalized);
        }
        else
        {   //in this case it can't hit the target (or barely can), so it shoots with the best aim
            float xs = Mathf.Abs(adjustedPosition.x) / (1 - speedRatioSq);
            return((targetPosition + xs * targetVelocity - shooterPosition).normalized);
        }
    }
Exemple #2
0
        public override void LogicalLateUpdate()
        {
            BaseCharacterControl vars = _sprayAttack.Holder;

            if (vars.Life.Health > _sprayAttack.MinLifeForDamageToSelf)
            {
                vars.Life.Damage(_sprayAttack, _sprayAttack.DamageToSelf);
            }
            if (!_gotInput)
            {
                _ASM.ChangeToInactive();
                return;
            }
            _sprayAttack.AngleDirection = MyMathlib.AngleRadians(vars.DirectionVector);
            _sprayAttack._audioSourceLoop.transform.position = _sprayAttack.MoveComponent.Position;
            Transform transform = _sprayAttack.transform;

            for (int i = 0; i < transform.childCount; i++)
            {
                if (!transform.GetChild(i).gameObject.activeSelf)
                {
                    transform.GetChild(i).gameObject.SetActive(true);
                }
            }
            _sprayAttack.CheckAndSetParticleNumber(_sprayAttack.NumberOfParticles);
            _gotInput = false;
        }
Exemple #3
0
    protected void OnEnable()
    {
        _v = new Vector3(Random.Range(FireAttack._ORIGINAL_HEIGHT / 0.3f, FireAttack._ORIGINAL_HEIGHT / 0.6f), Random.Range(-FireAttack._ORIGINAL_HALFWIDTH / 0.6f, FireAttack._ORIGINAL_HALFWIDTH / 0.6f));
        _v = MyMathlib.RotateVector(_v, _angleTemp = MyMathlib.PolarVectorDeg(transform.parent.rotation.eulerAngles.z)) + _fireAttack.MoveComponent.Velocity;
        transform.position = MyMathlib.RotateVector(Vector3.right, _angleTemp) + transform.parent.position;

        _coroutineTimer = this.DoActionInTime(() => gameObject.SetActive(false), _MAX_TIME_ON_AIR);
    }
Exemple #4
0
 private void LateUpdate()
 {
     transform.position += _v * Time.deltaTime;
     if (_fireAttack.Checkborders(MyMathlib.RotateVector(transform.position - transform.parent.position, MyMathlib.Conjugatevect(_angleTemp)) / 1.35f))
     {
         gameObject.SetActive(false);
         StopCoroutine(_coroutineTimer);
     }
     transform.localScale = new Vector3(1f, 1f);
 }
Exemple #5
0
    private void CheckAndFixDt()
    {
        if (_lastFixedFramerate != Time.fixedDeltaTime)
        {
            Directionrotatespeed = MyMathlib.PolarVectorDeg(_dwDegrees);
            _lastFixedFramerate  = Time.fixedDeltaTime;
#if UNITY_EDITOR
            Debug.Break();
            Debug.Log("framerate changed");
#endif
        }
    }
Exemple #6
0
 private void SetCurrentReach()
 {
     if (CurrentReach < _maxDistance)
     {
         CurrentReach += Speed * Time.fixedDeltaTime;
     }
     else
     {
         CurrentReach = _maxDistance;
     }
     if (CurrentReach > 1f)
     {
         Vector2 direction       = MyMathlib.PolarVector2Deg(_rigidBody.rotation);
         Vector2 currentPosition = transform.position;
         var     results         = Physics2D.LinecastAll(currentPosition + direction, currentPosition + (CurrentReach + 1f) * direction, gameObject.layer.GetLayerMask());
         if (results.Length > 0)
         {
             CollisionInfo collHit   = null;
             float         minDistSq = CurrentReach.Sq();
             for (int i = results.Length - 1; i >= 0; --i)
             {
                 var collInfo = results[i].collider.GetComponent <CollisionInfo>();
                 if (ApplyDamage(collInfo, 0f) || this.CheckToBlockAttack(collInfo))
                 {
                     float tempdistsq = (results[i].point - currentPosition).ProjectOnNormalisedVector(direction).sqrMagnitude;
                     if (tempdistsq < minDistSq)
                     {
                         minDistSq = tempdistsq;
                         collHit   = collInfo;
                     }
                 }
             }
             if (collHit != null)
             {
                 _maxDistance = Mathf.Sqrt(minDistSq) + 0.1f;
                 ApplyDamage(collHit, Damage);
             }
             else
             {
                 _maxDistance = Reach;
             }
         }
         else
         {
             _maxDistance = Reach;
         }
         if (CurrentReach > _maxDistance)
         {
             CurrentReach = _maxDistance;
         }
     }
 }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        var collparameters = collision.GetComponent <CollisionInfo>();

        this.CheckToBlockAttack(collparameters);

        if (ApplyDamage(collparameters, _damage))
        {
            MoveComponent collMoveComponent = collision.SearchComponent <MoveComponent>();
            collMoveComponent.Push(10f, _side * MyMathlib.Rotate90(_direction));
            _audio.AddSoundToQueue(0, transform.position);
        }
    }
Exemple #8
0
    protected override void InitiateAttack()
    {
        _tempDirection      = Holder.TargetPosition - MoveComponent.Position;
        _directionMagnitude = _tempDirection.magnitude;
        _tempDirection     /= _directionMagnitude;
        Drift = -Drift;

        _v = GetDistance() / 2f * _wDrift * MyMathlib.Rotate90(-_tempDirection);
        transform.position = MoveComponent.Position;
        _coll.enabled      = _rend.enabled = true;
        _maxTime           = 3f;
        ResetCoolDown();
    }
 protected new void Start()
 {
     _characters = new Transform[_numberOfTeams][];
     for (int i = 0; i < _characters.Length; i++)
     {
         _characters[i] = new Transform[_eachTeamNumber];
     }
     _centreSpawns = new Vector3[_characters.Length];
     for (int i = 0; i < _centreSpawns.Length; i++)
     {
         _centreSpawns[i] = MyMathlib.PolarVectorDeg(50f * MyMathlib.SQRT_OF_2, 50f * MyMathlib.SQRT_OF_2, 135f - i * 360 / _centreSpawns.Length);
     }
 }
Exemple #10
0
 protected override void InitiateAttack()
 {
     enabled = true;
     Radius  = 0f;
     TempDirectionOfParticle = Vector3.right;
     ParticleAngleDiffVector = MyMathlib.PolarVectorRad(MyMathlib.TAU / NumberOfParticles);
     Directionrotatespeed    = MyMathlib.PolarVectorDeg(_dwDegrees);
     _lastFixedFramerate     = Time.fixedDeltaTime;
     CheckAndSetParticleNumber(NumberOfParticles);
     for (int i = 0; i < NumberOfParticles; i++)
     {
         transform.GetChild(i).gameObject.SetActive(true);
     }
 }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        CollisionInfo collparameters = collision.GetComponent <CollisionInfo>();

        if (ApplyDamage(collparameters, _damage))
        {
            if (canPush)
            {
                Vector3 targ_sub_pos  = collparameters.transform.position - MoveComponent.transform.position;
                Vector3 directionSpin = -MyMathlib.Rotate90(targ_sub_pos);
                collparameters.Entity.MoveComponent.Push(push_distance, (targ_sub_pos + directionSpin).normalized);
            }
        }
    }
Exemple #12
0
    private void UpdateVelocity()
    {
        //v = v * (float)System.Math.Sqrt(1 - spin * spin * Time.fixedDeltaTime * Time.fixedDeltaTime) + spin * mathlib.rotate90(v) * Time.fixedDeltaTime;
        //v += wspin * mathlib.rotate90(v) * Time.fixedDeltaTime;
        //v = (v + wspin * Time.fixedDeltaTime * mathlib.rotate90(v)) / (1 + wspin * wspin * Time.fixedDeltaTime * Time.fixedDeltaTime);

        if (_outOfReach)
        {
            _v += _wDrift * Time.fixedDeltaTime * MyMathlib.Rotate90(_v);
        }
        else
        {
            float w2T2div4 = _wDrift * _wDrift * Time.fixedDeltaTime * Time.fixedDeltaTime / 4f;
            _v = ((1f - w2T2div4) * _v + _wDrift * Time.fixedDeltaTime * MyMathlib.Rotate90(_v)) / (1f + w2T2div4);
        }
    }
    protected void OnEnable()
    {
        _firstTime    = true;
        _coll.enabled = false;
        _rend.enabled = false;

        var angle = _sprayAttack.AngleDirection + Random.Range(-_sprayAttack.AngleSpreadRAD, _sprayAttack.AngleSpreadRAD) / 2f;

        _movement             = MyMathlib.PolarVectorRad(_sprayAttack.Speed, angle) + _sprayAttack.MoveComponent.Velocity;
        transform.eulerAngles = new Vector3(0, 0, angle * MyMathlib.RAD_TO_DEG);

        _maxTime = _sprayAttack.Reach / _sprayAttack.Speed;
        _time    = Random.Range(-_maxTime * 0.75f, 0); //wait a bit so the fire rate can be uniform and not all come out at the same time

        _damage = _sprayAttack.Damage;
    }
    protected override void InitiateAttack()
    {
        _direction          = Holder.TargetPosition - MoveComponent.Position;
        _directionMagnitude = _direction.magnitude;
        _direction         /= _directionMagnitude;

        _inputRadius = GeRadius();

        transform.localScale = new Vector3(Size, Size, 1f);
        _coll.enabled        = true;
        _rend.enabled        = true;
        _rotateSpeed         = MyMathlib.PolarVectorRad(W * _side * Time.fixedDeltaTime);
        ResetCoolDown();


        _side = -_side;
    }
 private void LateUpdate()
 {
     if (!_coll.enabled && _orbitAttack.Radius == _orbitAttack.MaxRadius)
     {
         _coll.enabled = true;
     }
     if (!_orbitAttack.OrbitThrown)
     {
         transform.position = _orbitAttack.MoveComponent.Position + _orbitAttack.Radius * (_direction = MyMathlib.RotateVector(_direction, _orbitAttack.Directionrotatespeed));
     }
     else
     {
         transform.position = _orbitAttack.Centre + _orbitAttack.Radius * (_direction = MyMathlib.RotateVector(_direction, _orbitAttack.Directionrotatespeed));
     }
 }
 public override void LogicalFixedUpdate()
 {
     _orbitClearAttack._direction = MyMathlib.MultiplyComplex(_orbitClearAttack._direction, _orbitClearAttack._rotateSpeed);
 }
    protected void OnEnable()
    {
        transform.position = _orbitAttack.MoveComponent.Position + _orbitAttack.Radius * (_direction = _orbitAttack.TempDirectionOfParticle = MyMathlib.RotateVector(_orbitAttack.TempDirectionOfParticle, _orbitAttack.ParticleAngleDiffVector));
        float size = _orbitAttack.ParticleSize;

        transform.localScale = new Vector3(size, size, 1f);
        _damage       = _orbitAttack.Damage;
        _coll.enabled = false;
    }