How to make the character jump while following a CinemachineSmoothPath,How to make the character jump while following a CinemachineSmoothPath track?

Hello, I am trying to make my character jump while he follows a CinemachineSmoothPath. My character uses the CinemachineDollyCart script to stay on the track. Whenever I try to make him jump though he immediately gets forced back on the track.

 private void Update()
    {
        if (isGrinding)
        {
            GrindingMovement();
            if (jumpAction.triggered)
            {
                Jump();
            }
            if (cmdc.m_Position == cmdc.m_Path.MaxPos)
            {
                StopGrinding();
            }
        }
    }
    public void Jump()
    {
        if (tpc.groundedPlayer)
        {
            tpc.JumpFormular();
            StopGrinding();
            Debug.Log("Grinding Jump");
        }
        playerVelocity.y += gravityValue * Time.deltaTime;
        controller.Move(playerVelocity * Time.deltaTime * cmdc.m_Speed);
    }
    public void JumpFormular()
    {
        playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
    }
    public void StopGrinding()
    {
        isGrinding = false;
        SwitchActionMap();
    }

    public void SwitchActionMap()
    {
        if (isGrinding)
        {
            tpc.GetComponent<PlayerInput>().SwitchCurrentActionMap("Grinding");
            moveAction = playerInput.actions["Move"];
            jumpAction = playerInput.actions["Jump"];
            //tpc.GetComponent<PlayerInput>().actions.FindActionMap("Player").Enable();
            // tpc.GetComponent<PlayerInput>().actions.FindActionMap("Grinding").Enable();
        }
        else
        {
            tpc.GetComponent<PlayerInput>().SwitchCurrentActionMap("Player");
            // tpc.GetComponent<PlayerInput>().actions.FindActionMap("Player").Enable();
            // tpc.GetComponent<PlayerInput>().actions.FindActionMap("Grinding").Disable();
        }
    }

Hello,

To make your character jump while it is following the CinemachineSmoothPath, you can try adding some additional logic to your Jump() function.

One approach you can take is to calculate the position of the character on the track when it starts the jump, and then update the position of the CinemachineDollyCart to match this position as the character is in the air. This will allow the character to move off the track while it is jumping, but will also ensure that it returns to the track once the jump is finished.

Here is an example of how you could implement this:

public void Jump()
{
    if (tpc.groundedPlayer)
    {
        // Calculate the position of the character on the track when it starts the jump
        float startTrackPosition = cmdc.m_Position;

        // Perform the jump
        tpc.JumpFormular();

        // Update the position of the CinemachineDollyCart to match the start position
        // as the character is in the air
        cmdc.m_Position = startTrackPosition;

        Debug.Log("Grinding Jump");
    }
    playerVelocity.y += gravityValue * Time.deltaTime;
    controller.Move(playerVelocity * Time.deltaTime * cmdc.m_Speed);
}

This code calculates the position of the character on the track when it starts the jump, and stores it in the startTrackPosition variable. It then performs the jump using the JumpFormular() function, and updates the position of the CinemachineDollyCart to match the start position as the character is in the air.

I hope this helps! Let me know if you have any further questions or if you need further clarification.