How to Make Object Move while Jumping

I am making a script that requires an object move while jumping. But when I make the object move to the right and then make it jump, it just jumps straight up. It doesn’t jump to the right, and same for the left. Here is my code:

---------------------------------------------------------------------------------------

#pragma strict 

var rotationSpeed = 150;

var jumpHeight = 5;

var jumpHeigtht2 = 0;

var isFalling = false;


function Update ()

{

// this is to Handle the Ball rotation.

var rotation : float = Input.GetAxis("Horizontal") * rotationSpeed;
 
rotation *= Time.deltaTime;

GetComponent(Rigidbody).AddRelativeTorque(Vector3.back * rotation);

// this is to help the ball jump.

if (Input.GetKey(KeyCode.W)&& isFalling == false)

{ 

GetComponent(Rigidbody).velocity.y = jumpHeight;

}
 
 
}
 
function OnCollisionStay ()

{ 

isFalling = false;

}
 
function OnCollisionExit ()

{ 

isFalling = true;

}

-------------------------------------------------------------------------------------

How do I fix this? Can anyone help?

I think its because when you jump using the rigidbody.velocity.y you are locking your x and z axis and unity only thinks your trying to move just the y axis my solution is to add the x and z axis as it is heres an example from a 2D game im working on add the z axis accordingly since your game is 3D.`

if(jump){
			GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x,jumpheight);} 

you see in my example i add the x axis as it is while manipulating the y axis making it so that the x is not locked hopes this helps