Ball Movement Issue

Hello everyone I am having a little issue with this simple project
I am making a 3d breakout game in which I want to make the ball move in X and Z direction respectively. I have used the code for ball movement from Unity’s Breakout game tutorial.

After using the code, the ball is only moving horizontally (X DIRECTION) at the same spot.

How do I make it move in z direction also freely

Thanks in advance

using UnityEngine;
using System.Collections;

public class Ball : MonoBehaviour {

    public float ballInitialVelocity= 600f;
    private Rigidbody rb;
    private bool ballInPlay;

    // Use this for initialization
    void Awake () {
   
        rb = GetComponent<Rigidbody> ();
    }
   
    // Update is called once per frame
    void Update () {
   
        if(Input.GetButtonDown("Fire1")&& ballInPlay == false)
        {
            transform.parent = null;
            ballInPlay = true;
            rb.isKinematic = false;
            rb.AddForce(new Vector3(ballInitialVelocity, ballInitialVelocity,0));

        }


    }
}

if you want x z you should do

rb.AddForce(new Vector3(ballInitialVelocity, 0, ballInitialVelocity));

don’t know what the rest of your scripts do, but that’s the only point you adding force to your ball

Thanks for the reply… It really worked… but I am facing an issue, whenever I play the game the ball slows down after each impact, and finally stop in between.
I guess the initial velocity of 600 zeros down that’s why the ball stops

please help me with this.

thanks in advance

Sounds like gravity and friction are working exactly as they should. Initial velocity and minimum velocity are two different concepts: are you wanting a minimum velocity?

You may also want to look into OnCollisionEnter and basically “re-impact” the ball each time it hits the paddle to add more force to it. I would also look into making gravity pull in the direction of the paddle instead, so that a minimum velocity won’t ever be necessary (it’ll just “fall down” toward the paddle if it loses momentum and allow you to re-impact it).