title: Shooting a ball (With gravity)
body: <p>I am currently having trouble shooting a ball and adding velocity to it. The idea is that the longer you hold down "SPACE" the longer the ball will travel.</p>
  
  <p><img src="https://i.imgur.com/FMZxiXG.png" alt="image"></p>
  
  <p>What I have so far is this for the player control:</p>
  
  <pre><code>public class PlayerControl : MonoBehaviour {
  
      public float speed = 0f;
      Vector3 enVector = new Vector3(10,0,0);
      public bool laserDirection = false;
  
      public Transform firePoint;
      public GameObject RedBall;
  
      public PlayerControl player;
  
      // Use this for initialization
      void Start () { }
  
      // Update is called once per frame
      void Update () 
      {
  
          // Press CTRL to move the platform under the ball and shoot a laser (NOT FINISHED)
          if (Input.GetKey (KeyCode.LeftControl) &amp;&amp; laserDirection == false) 
          {
              transform.Translate(enVector * -speed * Time.deltaTime);
          } 
          else if(Input.GetKey (KeyCode.LeftControl) &amp;&amp; laserDirection == true) 
          {
  
              transform.Translate(enVector * speed * Time.deltaTime);
          }
  
          // Sets the direction the platform will travel if pressed
          if(Input.GetKey (KeyCode.LeftArrow))
          {
              laserDirection = false;
          }
  
          // Sets the direction the platform will travel if pressed
          if(Input.GetKey (KeyCode.RightArrow))
          {
              laserDirection = true;
          }
  
          // Shoots a ball the longer you hold down
          if(Input.GetKey (KeyCode.Space))
          {
              GetComponent&lt;Rigidbody2D&gt; ().velocity = new Vector2 (speed, GetComponent&lt;Rigidbody2D&gt; ().velocity.y);
              Instantiate(RedBall, firePoint.position, firePoint.rotation);
          }
      }
  
      // Destroy the ball
      void OnTriggerEnter2D(Collider2D other) 
      {
          Destroy (gameObject);
      }
  }
  </code></pre>
  
  <p>If you look where the get space button is you see the code I've made for the shooting. This only makes the ball travel to the right at a set speed I've chosen.</p>
  
  <p>This is for changing the direction of the ball (It moves around the big black ball):</p>
  
  <pre><code>// THE DIRECTION OF THE BALL SCRIPT
  public class RedBall : MonoBehaviour 
  {
  
      public Transform target;
  
      void Update() 
      {
          // Moves the ball launcher  to the left
          if (Input.GetKey (KeyCode.LeftArrow)) 
          {
              transform.RotateAround (target.position, transform.forward, Time.deltaTime * 90f);
          }
  
          // Moves the ball launcher  to the right
          if (Input.GetKey (KeyCode.RightArrow)) 
          {
              transform.RotateAround (target.position, -transform.forward, Time.deltaTime * 90f);
          }
      }
  }
  </code></pre>
  
  <p>I am struggling with how to figure out how to make the ball shoot in the direction it is facing, which depends on how it has been translated in the ball script. Additionally, how to make the ball react to the gravity when shot and how to shoot further the longer I hold hold the "SPACE" button. </p>
  
  <p>If anyone knows how to do at least one of these things it would help a lot! Thank you.</p>