Esempio n. 1
0
        /// <summary>
        /// Triggered when a CorgiController collides with the surface
        /// </summary>
        /// <param name="collider">Collider.</param>
        public virtual void OnTriggerStay2D(Collider2D collider)
        {
            _controller = collider.gameObject.MMGetComponentNoAlloc <CorgiController>();
            _character  = collider.gameObject.MMGetComponentNoAlloc <Character>();

            if (_controller == null)
            {
                return;
            }

            bool found = false;

            foreach (SurfaceModifierTarget target in _targets)
            {
                if (target.TargetController == _controller)
                {
                    found = true;
                    target.TargetAffectedBySurfaceModifier = true;
                }
            }
            if (!found)
            {
                SurfaceModifierTarget newSurfaceModifierTarget = new SurfaceModifierTarget();
                newSurfaceModifierTarget.TargetController = _controller;
                newSurfaceModifierTarget.TargetCharacter  = _character;
                newSurfaceModifierTarget.TargetAffectedBySurfaceModifier = true;
                _targets.Add(newSurfaceModifierTarget);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// This method applies horizontal forces if needed
 /// </summary>
 /// <param name="target"></param>
 protected virtual void ApplyHorizontalForce(SurfaceModifierTarget target)
 {
     if (Time.time - target.LastForceAppliedAtX > ForceApplicationCooldownDuration.x)
     {
         if (ForceApplicationMode == ForceApplicationModes.AddForce)
         {
             _controller.AddHorizontalForce(AddedForce.x * 10f * Time.deltaTime);
         }
         else
         {
             _controller.SetHorizontalForce(AddedForce.x);
         }
         target.LastForceAppliedAtX = Time.time;
     }
 }
Esempio n. 3
0
 /// <summary>
 /// This method applies vertical forces if needed
 /// </summary>
 /// <param name="target"></param>
 protected virtual void ApplyVerticalForce(SurfaceModifierTarget target)
 {
     if (Time.time - target.LastForceAppliedAtY > ForceApplicationCooldownDuration.y)
     {
         if (ForceApplicationMode == ForceApplicationModes.AddForce)
         {
             float verticalForce = Mathf.Sqrt(2f * AddedForce.y * -_controller.Parameters.Gravity);
             _controller.AddVerticalForce(verticalForce);
         }
         else
         {
             _controller.SetVerticalForce(AddedForce.y);
         }
         target.LastForceAppliedAtY = Time.time;
     }
 }