How to shoot without bullets falling... RigidBody2D

This is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Shoot : MonoBehaviour {

    private Vector3 mousePosition;
    public float offset;
    public float movementSpeed;
    public Rigidbody2D bullet;

    // Use this for initialization
    void Start () {
       
    }
   
    // Update is called once per frame
    void Update () {
        if (Input.GetMouseButtonDown(0)) {
            Vector2 target = Camera.main.ScreenToWorldPoint( new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y) );
            Vector2 myPos = new Vector2(transform.position.x,transform.position.y + 1);
            Vector2 direction = target - myPos;
            Rigidbody2D projectile = Instantiate (bullet, transform.position, transform.rotation, null);
            projectile.GetComponent<Rigidbody2D> ().velocity = direction * 10;
        }
    }
}

I’m making a 2D tank game which this player is controlled by the mouse. I’m trying to get it so the bullet goes towards the mouse position. For a long time the bullet was not moving because I disabled RigidBody2D on the bullet prefab… but now when I shoot the bullet falls down with gravity! How do I disable gravity in 2D, and how can I get the bullet to shoot straight? I’ve been trying to figure this out for two days now. :frowning:

Set the gravity scale to 0 on your bullet?

You can set the gravityscale from the editor, in the rigidbody2D component, you can also do it in the start function this way :
bullet.gravityScale = 0;

Thanks, I forgot to look at the gravity scale! :smile: It works now. Unfortunately, things are still not shooting straight. :frowning:

Never mind, I fixed it! My code was WAY too long!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Shoot : MonoBehaviour {
   
    public Rigidbody2D bullet;

    void Update () {
        if (Input.GetMouseButtonDown(0)) {
            Rigidbody2D projectile = Instantiate (bullet, transform.position, transform.rotation, null);
            projectile.GetComponent<Rigidbody2D> ().velocity = transform.parent.right * 20;
        }
    }
}