Move in direction of mouse

I’m pretty new to Unity and the whole library that comes with it, so I’m still getting my footing here.

I’m making a 2d arcade-style space shooter similar to Geometry Wars or other similar games. I want the bullet to project in the direction of the mouse’s click, regardless of the direction that the ship is facing. I’ve been toying around with all kinds of Vector3/Quaternion stuff and I haven’t had any luck. My code in the player script looks like this:

if (Input.GetMouseButtonDown(0)) {
    bullpath = Input.mousePosition;
    socketBullet.rotation.SetLookRotation(bullpath, Vector3.up);
    Instantiate (bullet1, socketBullet.position, socketBullet.rotation);
}

Where bullpath is a Vector3 and socketBullet is a Transform that is the origin of the bullet.

THEN, in the bullet script, I use:

void Update () {
	transform.position += transform.up * speed * Time.deltaTime;
	Destroy(gameObject, lifespan);
	}

I’m sure that I’m missing one simple thing that I don’t know simply because I’m new to the tools that Unity provides, but as it stands the bullet will only fire in the direction that the ship is facing. I can, of course, control the direction the ship is facing with WASD and the bullet will fire in a straight line from the front, when I want it to fire in a straight line toward wherever the mouse was clicked.

Any help is greatly appreciated.

In your bullet’s spawn, on Start find the mouse position. Because screen space is 2d, and the world is 3d, you’ll have to use ScreenToWorldPoint and head towards that location. You’ll likely want to move there by lerping the Vector3s. To do this more smoothly, do something with Time.deltaTime;

With this, the bullets should Spawn and then simply move to where the mouse was when it spawned.

You probably want to do this:

Plane castedPlane = new Plane(Vector3.up,Vector3.zero); //That is if your game is on XZ plane, else you should change this line
if (Input.GetMouseButtonDown(0)) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    				float ent;
    				if (castedPlane.Raycast(ray,out ent)){
    					Vector3 hitPoint = ray.GetPoint(ent);
    					socketBullet.rotation = Quaternion.LookRotation((hitPoint - socketBullet.position).normalized);
    				}
Instantiate (bullet1, socketBullet.position, socketBullet.rotation);
}

You can optimize code to not Raycast if you are using orthogonal camera. Not so necessary though.