Example #1
0
 void Awake()
 {
     _forcePhysics             = new GravityForce();
     _registeredBodies         = new List <IntSatData>();
     _parent                   = transform.GetComponentInParent <MovementBehaviour>();
     _satelliteManagerBehavior = GetComponentInParent <SatelliteManager>();
 }
Example #2
0
        private void Pull(IntSatData satellite, MovementBehaviour parent, float gravityForce)
        {
            var force = _forcePhysics.PullForceFabricMethod(
                parent,
                satellite.MovementBehaviour.transform.position,
                gravityForce);

            satellite.MovementBehaviour.SmoothlySetVelocity(force);
        }
Example #3
0
        private void OnCollisionEnter2D(Collision2D collision)
        {
            if (!CollisionEnabled ||
                !LayerHelper.IsBody(collision.gameObject.layer))
            {
                return;
            }

            MovementBehaviour enemy = collision.gameObject.GetComponent <MovementBehaviour>();

            if (Magnitude > enemy.Magnitude)
            {
                var     speed1       = Velocity.normalized * 0.05f;
                Vector2 normal       = collision.contacts[0].normal;
                var     reflect      = Vector2.Reflect(speed1, normal);
                var     reflectEnemy = reflect * -0.99f;
                SetVelocity(reflect);
                enemy.SetVelocity(reflectEnemy);
            }
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="possibleSatellite">Объект который вошел в зону влияния(притяжения)</param>
        /// <param name="parentalObject">Объект который тянет</param>
        /// <returns></returns>
        private bool CheckEntryIntoOrbit(
            IntSatData possibleSatellite,
            MovementBehaviour parentalObject)
        {
            possibleSatellite.TimeLeftTillNextCheck -= Time.fixedDeltaTime;
            if (possibleSatellite.TimeLeftTillNextCheck > 0)
            {
                return(false);
            }
            possibleSatellite.TimeLeftTillNextCheck = DeltaTimeTillOrbit;

            float distanceBeetwenPoints = Vector3.Distance(
                parentalObject.transform.position,
                possibleSatellite.MovementBehaviour.transform.position);

            //Debug.Log($"{_minR} < {distanceBeetwenPoints} < {_maxR}");

            if (!(_minR < distanceBeetwenPoints &&
                  _maxR > distanceBeetwenPoints))
            {
                possibleSatellite.TimeLeftTillNextCheck = 0;
                possibleSatellite.HitsBeforeOrbit       = 0;
                possibleSatellite.TempI = 0;
                return(false);
            }
            possibleSatellite.TempI++;
            //Debug.Log("Hit: " + possibleSatellite.TempI);
            //Ждем пока объект попадет под влияние положеннное количество раз
            if (possibleSatellite.TempI < _iterateCheckEntryOfOrbit)
            {
                return(false);
            }

            //если опрделенное количество проверок пройдено, то делаем его спутником
            _satelliteManagerBehavior.AttachSatellite(possibleSatellite, parentalObject);
            CalculateInfluenceRadius();
            return(true);
        }