How to shoot projectile towards touch position for mobile?

I am completely lost with touch position compared to world/screen space. All i would like to do it be able to touch on the screen and shoot a projectile from the player position (which is in the center of the screen with the camera a child of the player) towards the touched position for mobile application. Right now when I shoot the projectile, I have it going towards the touch position, but it goes in world space and disappears on the z axis. I’ve tried locking the z axis, I’ve tried changing the screen point, but nothing seems to work. Any help would be fantastic as it may be something simple that I am overlooking or not knowing about. Thank you for all help.

current instantiating projectile script here -

if (Input.touchCount > 0) {

			if (Input.GetTouch (0).phase == TouchPhase.Began) {

				Vector3 touchPosition = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
				GameObject bullet = Instantiate (projectile, transform.position, Quaternion.identity)as GameObject;
				bullet.transform.LookAt (touchPosition);

current script attached to projectile -

transform.position += transform.forward * bulletSpeed * Time.deltaTime;

I took a few things from the comments on the initial question and added some changes. Thanks for pointing me to the right direction to find the answer everyone. Here is the final script and it works perfectly.

using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;

public class Shooting : MonoBehaviour {

	public GameObject projectile;
	public float bulletSpeed;

	void Update () {
		if (Input.touchCount > 0) {

			if (Input.GetTouch (0).phase == TouchPhase.Began) {

				Vector2 touchPos = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
				Vector2 dir = touchPos - (new Vector2(transform.position.x, transform.position.y));
				dir.Normalize ();
				GameObject bullet = Instantiate (projectile, transform.position, Quaternion.identity)as GameObject;
				bullet.GetComponent<Rigidbody2D> ().velocity = dir * bulletSpeed; 

There is a function called ScreenPointToRay. This function creates a ray from camera to point on the screen.

    Ray r = Camera.main.ScreenPointToRay(Input.mousePosition);
    Debug.DrawRay(r.origin, r.direction * 10, Color.cyan);

You need a direction vector and you can get that from above code. Replace mouse position with your touch position. You need to move your projectile along the ray’s direction. And you can instantiate your bullet like this:

GameObject bullet = Instantiate (projectile, transform.position, Quaternion.LookRotation(r.direction))as GameObject;

I hope this helps.

First of all you are using Camera.main.ScreenToWorldPoint() wrong. You pass it touch position, but touch position only has x and y values, z is zero, but ScreenToWorldPoint won’t work without z coordinate.

If your game is 2D it’s pretty easy to calculate correct z, here’s the example:

Camera.main.ScreenToWorldPoint(new Vector3(
    -Camera.main.transform.position.z + zPositionOfTheObjectYouWillRotate));

The second thing that could cause problems is LookAt() method, it has a second parameter which tells which way is the world up direction.

bullet.transform.LookAt(touchPosition, Vector3.forward);

I think this should do the trick, but if it doesn’t play around with the second parameter.