gameobject lerps forward only.

i am trying to move a game-object towards hit.point gradually but the result is that moves only forward for some reason. here is my problem:

1)i select the game object.
2)i left click to a point on my terrain ( it’s a plane).
3) the game object just moves a small portion forward. ignoring what ever direction my point was in.
3) i left click again. moves forward same pace. no matter how far or close the point is.

i am a beginner so bear with me please.

using UnityEngine;
using System.Collections;

public class ObjectMovement : MonoBehaviour {

public Camera mainCamera;
public float speed;

private Ray movementRay;
private RaycastHit hit;
public static Transform startPoint;
public static Transform endPoint;

private void Update () {
	movementRay = mainCamera.ScreenPointToRay (Input.mousePosition);
	if (ObjectSelection.selectedObject != null) {
		if (ObjectSelection.selectedObject.GetComponent<TankLogic> ()!= null ||
		    ObjectSelection.selectedObject.GetComponent<BuilderLogic>() != null) {
				if(Physics.Raycast(movementRay,out hit)&&Input.GetButtonDown("LeftClick")){
					endPoint = hit.transform;
					float distance=Vector3.Distance(startPoint.position, endPoint.position);
					if(distance>0) {
						ObjectSelection.selectedObject.transform.position = 


any help would be appreciated. my game object is massive scale is (2000,2000,2000) if that would make any difference.

You should use a coroutine for that. This:

if(Physics.Raycast(movementRay,out hit)&&Input.GetButtonDown("LeftClick"))

is valid only when you click, and this is why Lerp() is done only once.
So do the following (for example, you could just use a boolean):


IEnumerator LerpPosition()
	Vector3 startPos = ObjectSelection.selectedObject.transform.position;

	while(Vector3.Distance(startPos, endPoint.position) > 0.1) // endPoint is your hit setted as an attribute
		startPos = Vector3.Lerp(startPos, endPoint.position, Time.deltaTime); // this is smooth and cool
		yield return null;

Currently when you’re calculating the lerp value and updating the position, it’s confined within a “if(Input.GetButtonDown())” statement. This means it will only ever update when the mouse button is clicked down. If you store the values of the end point and start point when the mouse button is clicked and then call them outside this statement but still within the Update call, it will update the position.