Moving Player to clicked location on X and Z only?

Hi, I’m attempting to move my player towards the clicked location on the X and Z axis only. For some reason the code I’ve been using below only moves on the X and Y axis and I cannot seem to fix this.

void Update () {
		if (Input.GetMouseButton(0)) {
			var targetPos = (Input.mousePosition);
			transform.position = Vector3.MoveTowards(transform.position,targetPos, speed * Time.deltaTime);

	}
	}

Any help would be great

Input.mousePosition gives the pixel coordinates on the screen - so (0, 0, 0) if the mouse is at the lower left of the screen, and (screen width, screen height, 0) if the mouse is at the upper right.

In the docs for mousePosition, you can see how you use it to get the world position of the mouse in a 3D environment:

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public GameObject particle;
    void Update() {
        if (Input.GetButtonDown("Fire1")) {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray))
                Instantiate(particle, transform.position, transform.rotation) as GameObject;
            
        }
    }
}

Maybe I can point you in the right direction.

List of Controllers (very useful)

http://wiki.unity3d.com/index.php/Scripts/Controllers

Click Character Controller (The specific controller you are looking for)

http://wiki.unity3d.com/index.php/ClickCharacterController