Jump/move script doesnt work properbly

Hey there

Im trying to make a platform 2d game, but im already facing problems. Im having my character with a character controller on, and then im using this script

using UnityEngine;
using System.Collections;

public class PlayerScript : MonoBehaviour {
	public float speed = 6.0F;
	public float jumpSpeed = 8.0F;
	public float gravity = 20.0F;
	private Vector3 moveDirection = Vector3.zero;
	void Update() {
		CharacterController controller = GetComponent<CharacterController>();
		if (controller.isGrounded) {
			moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
			moveDirection = transform.TransformDirection(moveDirection);
			moveDirection *= speed;
			if (Input.GetButton("Jump"))
				moveDirection.y = jumpSpeed;
			
		}
		moveDirection.y -= gravity * Time.deltaTime;
		controller.Move(moveDirection * Time.deltaTime);
	}
}

It is working fine, but when i increase the speed of my character and the pressing jump, i am kinda running very fast. It’s like the jump doesnt work, when i am walking at the same time.
What could that be?

Kind regards
Mads

I believe this is why jump is not working when you are moving:

 moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

What is happening is that the code above is setting the y value of move direction as well, thus overriding:

moveDirection.y = jumpSpeed;

by setting the y value to 0.

So, change:

moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

to:

moveDirection = new Vector3(Input.GetAxis("Horizontal"), moveDirection.y, Input.GetAxis("Vertical"));