/// <summary> /// Stops the character from pushing or pulling /// </summary> protected virtual void StopPushing() { if (_pushedObject == null) { return; } _pushedObject.Detach(_controller); _pushedObject = null; _character.CanFlip = true; _characterHorizontalMovement.PushSpeedMultiplier = _movementMultiplierStorage; _pulling = false; }
/// <summary> /// Every frame we override parameters if needed and cast a ray to see if we're actually pushing anything /// </summary> public override void ProcessAbility() { base.ProcessAbility(); if (!CanPush || !AbilityPermitted) { return; } CheckForPushEnd(); // if we're button based we only proceed if the push button is being pressed if (ButtonBased && (_character.CharacterType == Character.CharacterTypes.Player) && (_inputManager.PushButton.State.CurrentState != MMInput.ButtonStates.ButtonPressed)) { return; } // we set our flag to false _collidingWithPushable = false; // we cast a ray in front of us to see if we're colliding with a pushable object _raycastDirection = _character.IsFacingRight ? transform.right : -transform.right; // Added offset for Raycast vertical position Vector3 raycastVerticalOffset = Vector3.zero; raycastVerticalOffset.y = (_controller.Height() / 2 * RaycastVerticalPostion); _raycastOrigin = _controller.ColliderCenterPosition + _raycastDirection * (_controller.Width() / 2) + raycastVerticalOffset; // we cast our ray to see if we're hitting something RaycastHit2D hit = MMDebug.RayCast(_raycastOrigin, _raycastDirection, DetectionRaycastLength, _controller.PlatformMask, Color.green, _controller.Parameters.DrawRaycastsGizmos); if (hit) { if (hit.collider.gameObject.MMGetComponentNoAlloc <Pushable>() != null) { _collidingWithPushable = true; } } // if we're colliding with a pushable and are in the right conditions, we start pushing if (_controller.State.IsGrounded && _collidingWithPushable && Mathf.Abs(_controller.ExternalForce.x) >= MinimumPushSpeed && _movement.CurrentState != CharacterStates.MovementStates.Pushing && _movement.CurrentState != CharacterStates.MovementStates.Jumping) { if (_movement.CurrentState == CharacterStates.MovementStates.Running) { if (_characterRun != null) { _characterRun.RunStop(); } } PlayAbilityStartFeedbacks(); _movement.ChangeState(CharacterStates.MovementStates.Pushing); } if (hit && (_movement.CurrentState == CharacterStates.MovementStates.Pushing) && (_pushedObject == null)) { _pushedObject = hit.collider.gameObject.MMGetComponentNoAlloc <Pushable>(); _pushedObject.Attach(_controller); _character.CanFlip = false; _movementMultiplierStorage = _characterHorizontalMovement.PushSpeedMultiplier; _characterHorizontalMovement.PushSpeedMultiplier = _pushedObject.PushSpeed; } if (((_controller.Speed.x > MinimumPushSpeed) && (_movement.CurrentState == CharacterStates.MovementStates.Pushing) && (_pushedObject.transform.position.x < this.transform.position.x)) || ((_controller.Speed.x < -MinimumPushSpeed) && (_movement.CurrentState == CharacterStates.MovementStates.Pushing) && (_pushedObject.transform.position.x > this.transform.position.x))) { if (!CanPull) { StopPushing(); } else { _pulling = true; } } else { _pulling = false; } }