Пример #1
0
        private void Attract(GravityAttractive objToAttract)
        {
            if (IsTryAttractOwnMissile(objToAttract))
            {
                return;
            }

            var direction = transform.position - objToAttract.transform.position;
            var distance  = direction.magnitude;

            var forceMagnitude = G * (mass * objToAttract.mass) / Mathf.Pow(distance, 2);
            var force          = direction.normalized * forceMagnitude;

            var rbToAttract = objToAttract.GetComponent <Rigidbody>();

            rbToAttract.AddForce(force);
        }
Пример #2
0
 private bool IsTryAttractOwnMissile(GravityAttractive objToAttract)
 {
     return(objToAttract.TryGetComponent(out Missile missile) && missile.parent == gameObject);
 }