Help, player only jumping occasionally :(

Here is the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    private CharacterController controller;
    private Vector3 direction;
    public float forwardSpeed;

    private int desiredLane = 1;//0:left 1:middle 2:right
    public float laneDistance = 4;// distance beetween two lanes

    public float JumpForce;
    public float Gravity = -20;
    void Start()
    {
        controller = GetComponent<CharacterController>();
    }

    private void Jump()
    {
        direction.y = JumpForce;
    }

    // Update is called once per frame
    void Update()
    {
        direction.z = forwardSpeed; {}

        //Gather the imputs on which lane we should be

        if(Input.GetKeyDown(KeyCode.RightArrow))
        {
            desiredLane++;
            if(desiredLane==3)
            desiredLane = 2;
        }
       
        if(Input.GetKeyDown(KeyCode.LeftArrow))
        {
            desiredLane--;
            if(desiredLane == -1)
            desiredLane = 0;
        }

        //Calculate where we should be on the future

        Vector3 targetPosition = transform.position.z * transform.forward + transform.position.y * transform.up;

        if (desiredLane ==0)
        {
            targetPosition += Vector3.left * laneDistance;

        }else if (desiredLane ==2)
        {
            targetPosition += Vector3.right * laneDistance;
        }

        transform.position = Vector3.Lerp(transform.position, targetPosition,50 * Time.fixedDeltaTime);

        if(controller.isGrounded)
        {  
           
            if(Input.GetKeyDown(KeyCode.UpArrow))
           {
            Jump();

           }
        }
        
        else
        {
            direction.y += Gravity * Time.deltaTime;
        }
        
        
         

      
       
    }


    private void FixedUpdate()
    {
        controller.Move(direction*Time.fixedDeltaTime);  
    }

   
}

The mistake you’re making is that you’re trying to move your character around with controller.Move and transform.position at the same time. Instead you should just use controller.Move from within Update, not FixedUpdate.

using UnityEngine;
public class PlayerController : MonoBehaviour
{
    private CharacterController controller;
    private Vector3 velocity;
    public float forwardSpeed;
    private int desiredLane = 1;//0:left 1:middle 2:right
    public float laneDistance = 4;// distance beetween two lanes
    public float JumpForce;
    public float Gravity = -20;
    float leftLanePosition;

    void Start()
    {
        controller = GetComponent<CharacterController>();
        leftLanePosition=transform.position.x-laneDistance;  // Get the left lane position by assuming the player is starting in the middle lane
        velocity.z = forwardSpeed;
    }
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.RightArrow) && desiredLane<2)
            desiredLane++;
        else if (Input.GetKeyDown(KeyCode.LeftArrow) && desiredLane>0)
            desiredLane--;
        float targetPosition = leftLanePosition + desiredLane * laneDistance; // Calculate where we should be in the future

        velocity.x=(targetPosition-transform.position.x)*10; // Set velocity x so we head towards the target

        if (controller.isGrounded)
        {
            if (Input.GetKeyDown(KeyCode.UpArrow))
                velocity.y = JumpForce;
        }
        else
            velocity.y += Gravity * Time.deltaTime;

        controller.Move(velocity * Time.deltaTime);
    }
}