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 IEnumerator ReturnAnimation(IPhysicable physicable)
    {
        var body = physicable.GetBody();

        body.isKinematic = false;
        body.useGravity  = true;

        yield return(new WaitForSeconds(_physicTime));

        if (!body)
        {
            yield break;
        }

        body.useGravity  = false;
        body.isKinematic = true;

        _waitingObjects.Remove(physicable);

        Spawner.Instance.ReturnToSchedule(physicable as ISpawnable);
    }
Ejemplo n.º 3
0
 private void OnPhysicsGenerated(IPhysicable sender)
 {
     this.breakableBody             = (BreakableBody)this.physics.FixtureData;
     this.breakableBody.Decomposed += this.OnBreakableBodyDecomposed;
 }
Ejemplo n.º 4
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);
        }