/// <summary>
        /// Throws the carried object
        /// </summary>
        protected virtual void Throw()
        {
            if (CarriedObject == null)
            {
                return;
            }

            int direction = _character.IsFacingRight ? 1 : -1;

            CarriedObject.Throw(direction, ThrowForce);

            // apply recoil
            if (RecoilModifier != 0f)
            {
                _recoilVector  = (direction == 1) ? Vector2.left : Vector2.right;
                _recoilVector *= RecoilModifier * CarriedObject.Recoil;
                _controller.AddForce(_recoilVector);
            }

            StopFeedbacks();
            CarriedObject = null;
            CarryingID    = -1;
            Carrying      = false;
            Throwing      = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Tries to grab by casting a raycast
        /// </summary>
        protected virtual void GrabAttempt()
        {
            _raycastOrigin = this.transform.position;
            RaycastHit2D hit = MMDebug.RayCast(_raycastOrigin, RaycastDirection, RaycastDistance, DetectionLayerMask, Color.blue, _controller.Parameters.DrawRaycastsGizmos);

            if (hit)
            {
                // we make sure we have an object that can be carried
                CarriedObject = hit.collider.gameObject.MMGetComponentNoAlloc <GrabCarryAndThrowObject>();
            }
            if (CarriedObject != null)
            {
                Grab();
            }
        }