About Click to move...

I have this Click to move script

var smooth:int;

private var targetPosition:Vector3;

function Update () {
if(Input.GetKey(KeyCode.Mouse0))
{
var playerPlane = new Plane(Vector3.up, transform.position);
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hitdist = 0.0;

if (playerPlane.Raycast (ray, hitdist)) {
var targetPoint = ray.GetPoint(hitdist);
targetPosition = ray.GetPoint(hitdist);
var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
transform.rotation = targetRotation;
}
}

transform.position = Vector3.Lerp (transform.position, targetPosition, Time.deltaTime * smooth);
}

why when the smooth its not 0 the cube the current player goes underneath the plane when its 0 its normal its up at the plane any ideas?

Please use code tags when posting code

Smooth is an int, and should be a float and greater than zero. So if smooth is zero. Time.deltaTime * zero is always zero. so it will never move.

var smooth : float=2.0;

private var targetPosition : Vector3;

function Update () {
	if(Input.GetKey(KeyCode.Mouse0))
	{
		var playerPlane = new Plane(Vector3.up, transform.position);
		var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
		var hitdist = 0.0;

		if (playerPlane.Raycast (ray, hitdist)) {
			targetPosition = ray.GetPoint(hitdist);
			//var targetRotation = Quaternion.LookRotation(targetPosition - transform.position);
			//transform.rotation = targetRotation;
			transform.LookAt(targetPosition);
		}
	}

	transform.position = Vector3.Lerp (transform.position, targetPosition, Time.deltaTime * smooth);
}