示例#1
0
    /**
     * This coroutine waits for the moment where this object is supposed to connect to the ground after being thrown.
     */
    private IEnumerator FallStopper(float stopTime, Vector2 antiThrowImpulse, ForceEffect airResistanceEffect, [CanBeNull] ForceEffect gravityEffect)
    {
        yield return(new WaitForSeconds(stopTime));

        // Remove all forces which simulated the flow
        _physicsEffects.RemoveForce(airResistanceEffect);
        if (gravityEffect != null)
        {
            _physicsEffects.RemoveForce(gravityEffect);
        }
        // Cancel out the impulse which initiated the throw and prevent this object from sliding forever by reenabling
        // friction
        _physicsEffects.ApplyImpulse(antiThrowImpulse);
        _physicsEffects.FrictionEnabled = true;

        // restore sorting order & collision between the carrier and this object, as this object lands on the ground
        this.gameObject.layer = _cachedLayer;
        Physics2D.IgnoreCollision(_collider, _carrier.Collider, false);
        _renderer.sortingOrder--;

        foreach (var interactive in GetComponents <Interactive>())
        {
            interactive.enabled = true;
        }

        // While being thrown, we might loose contact to safe terrain, so we registered this behavior as terrain unsafe
        // for respawning.
        // Now that the throw has finished, we can unregister it again.
        if (TryGetComponent <Spawnable>(out var spawnable))
        {
            spawnable.UnregisterTouchingUnsafeTerrain(this);
        }

        OnLanded?.Invoke();
    }
示例#2
0
    /**
     * Applies a force which will be continuosly applied to this object.
     *
     * In contrast to `AddForce` of Rigidbody2D, this class keeps track of the individual forces being applied and
     * returns a handle to the force effect.
     * This handle can be used to remove the force later.
     */
    public ForceEffect ApplyForce(Vector2 force)
    {
        var effect = new ForceEffect(force);

        _effectsForces.Add(effect);

        return(effect);
    }
示例#3
0
 public SkillHit(float times, MessagesType message, ForceEffect forcee, bool isdestroy, bool closecollider, bool charm, bool usereturn)
 {
     Times         = times;
     Message       = message;
     ForceE        = forcee;
     IsDestroy     = isdestroy;
     CloseCollider = closecollider;
     Charm         = charm;
     UseReturn     = usereturn;
 }
示例#4
0
    private void EvaluateForces()
    {
      // Store the old forces in this list.
      _tempForceList.Clear();
      //_tempTorqueList.Clear();

      // Set accumulated force/torque to force of user.
      int numberOfRigidBodies = RigidBodies.Count;
      for (int i = 0; i < numberOfRigidBodies; i++)
      {
        RigidBody body = RigidBodies[i];
        _tempForceList.Add(body.AccumulatedForce);
        //_tempTorqueList.Add(body.AccumulatedTorque);

        body.AccumulatedForce = body.UserForce;
        body.AccumulatedTorque = body.UserTorque;
      }

      // ----- Apply force effects.
      try
      {
        // Copy force effects into a temporary list, so that force effects can remove themselves 
        // from the force effects collection if they want to.
        foreach (var forceEffect in ForceEffects)
          _tempForceEffects.Add(forceEffect);

        int numberOfForceEffects = _tempForceEffects.Count;
        for (int i = 0; i < numberOfForceEffects; i++)
        {
          ForceEffect force = _tempForceEffects[i];
          force.Apply();
        }
      }
      finally
      {
        _tempForceEffects.Clear();
      }

      // Wake up bodies when there is a significant force change.
      // TODO: Torque changes do not yet wake up bodies!
      for (int i = 0; i < numberOfRigidBodies; i++)
      {
        RigidBody body = RigidBodies[i];

        // Wake body up if the force change would cause an acceleration equal to the sleep velocity
        // threshold.
        if ((_tempForceList[i] - body.AccumulatedForce).LengthSquared() > Settings.Sleeping.LinearVelocityThresholdSquared * body.MassFrame.Mass * body.MassFrame.Mass)
        {
          body.WakeUp();
        }
      }
    }
示例#5
0
 /**
  * Remove a force.
  * This also removes any velocity already induced by the force.
  */
 public void RemoveForce(ForceEffect forceEffect)
 {
     _effectsForces.Remove(forceEffect);
 }