Moving forward whilst jumping

I’m working on a game where the player is constantly running (third person) and has the ability to jump. With my script at the moment, when the player jumps (achieved by an upwards swipe on android in another script), the player stops moving forward and jumps, then returns to moving forward. I want it so that he jumps and continues but everything I try seems to not work. Any ideas? I’ve added some of the code with irrelevant parts removed. Thank you.

function Update() {

    var controller : CharacterController = GetComponent(CharacterController);
    if (controller.isGrounded && deadPlayer == false) {
        // We are grounded, so recalculate
        // move direction directly from axes to keep right direction after turn


        moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
                                Input.GetAxis("Vertical"));
        moveDirection = transform.TransformDirection(moveDirection);
        moveDirection *= speed;
        isMoving = true;
        
        var MoveDirection = transform.forward;
        controller.Move(MoveDirection * Time.deltaTime * speed); 
        
        // Tilt controls
       //direction.x = -Input.acceleration.y * moveSpeed;

         direction.x = Input.acceleration.x * moveSpeed;
 
        if (direction.sqrMagnitude > 1)
        direction.Normalize();
         
        // Make it move 10 meters per second
        direction *= Time.deltaTime;
		direction = Camera.main.transform.TransformDirection(direction); 
		// Move object without transform to take boundaries into consideration
		controller.Move (direction * speed);
        
        if (jump == true) {
            moveDirection.y = jumpSpeed;
            camera1.audio.PlayOneShot(jumpSound);
            isJumping = true;  
            jump = false;
            
                } 

         else
        	{
        	isJumping = false;
       	} 
       		
		 moveDirection.y -= gravity * Time.deltaTime;
		 controller.Move(moveDirection * Time.deltaTime); 

            }

Hello

Here is the fixed up code:

//Firstly move the controller variable outside of the update loop (optimisation)
var controller:CharacterController;
var moveDirection:Vector3;

function Awake() {
    //Only once find the character controller using the fastest method
    controller = GetComponent(typeof(CharacterController)) as CharacterController;
}

function Update() {
    //I removed a large amount of code, since it seemed it was never used
    //The first thing we should do is calculate the local direction we should move in
    
    if (deadPlayer == false) {
        //We arent dead, so we can move
        //Calculate the movement speed according to accelerometer
        moveDirection.x = Input.acceleration.x*speed;
        //Now the constant moving forward
        moveDirection.z = speed;
        
        /*If you want to be able to move with the axis as well, just un-comment this:
        moveDirection.x += Input.GetAxis("Horizontal")*speed;
        */
        
        //I didn't change your jumping
        if (jump == true && controller.isGrounded) {
            //Only Jump when grounded
            moveDirection.y = jumpSpeed;
            camera1.audio.PlayOneShot(jumpSound);
            isJumping = true;  
            jump = false;
        }
        else {
            isJumping = false;
        } 
    }

    //Now we move, and only once
    moveDirection.y -= gravity * Time.deltaTime;
    controller.Move(Camera.main.transform.TransformDirection(moveDirection) * Time.deltaTime);
}

I believe this is what you are looking for.
Any problems? Don’t hesitate to ask

Benproductions1

@Benproductions1 i need controller something like
Character should move forward and jump parabolic continually ,and right life on swiping left or right how can i achieve it,?

moveDirection.y += jumpSpeed;