Moving forward whilst jumping (501388)

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. I realise it’s not the most elegant code but for the moment I’m just trying to get this working so I can make other progress. 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); 

                }

you call it three times per Update… and you also have a variable called “MoveDirection” (line 15/16) and one called “moveDirection” and you also use “direction”…

If you look at the example on that reference page you’ll see that they work out a single moveDirection vector based on the input, then apply it once at the end of the script with a call to CharacterController.Move. In your case of constant forward movement you can start with a Vector3.forward instead of using input for that component, then modify its horizontal component for the horizontal input and it’s vertical component based on whether it’s jumping and applying gravity. Once built you pass it to the Move function.

and a completely unrelated tip; if you put line 3 in the start/awake functions you only have to look up the controller once, not once per frame.