Ejemplo n.º 1
0
        public void ApplyGravityTo(IGravityReceivingEntity entity)
        {
            GravityReceiving gravity = entity.GravityReceiver;

            if (gravity.IsEnabled)
            {
                IPhysicable receivingPhysics = entity.Physics;

                Vector2 delta    = this.emittingPhysics.Center - receivingPhysics.Center;
                float   distance = delta.SquaredLength;

                if (distance != 0.0f)
                {
                    float   strength = CalculateGravityStrength(distance, gravity, receivingPhysics);
                    Vector2 force    = delta.Direction * strength;

                    receivingPhysics.ApplyForce(force);
                }
            }
        }
Ejemplo n.º 2
0
        private float CalculateGravityStrength(float squaredDistanceBetweenEmitterAndReceiver, GravityReceiving gravityReceiving, IPhysicable receivingPhysics)
        {
            float factor   = gravityReceiving.Factor * 0.001f;
            float strength = factor * ((this.emittingPhysics.Mass * receivingPhysics.Mass) / squaredDistanceBetweenEmitterAndReceiver);

            return(strength);
        }